Skip to content

Commit

Permalink
removing old code
Browse files Browse the repository at this point in the history
  • Loading branch information
labhvam5 committed Nov 8, 2023
1 parent bcbb759 commit be7b007
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,54 +142,6 @@ def disable_or_enable_expense_attributes(source_field: str, destination_field: s
return expense_attributes_ids


def create_fyle_projects_payload(projects: List[DestinationAttribute], existing_project_names: list, updated_projects: List[ExpenseAttribute] = None):
"""
Create Fyle Projects Payload from QBO Customer / Projects
:param projects: QBO Projects
:param existing_project_names: Existing Projects in Fyle
:return: Fyle Projects Payload
"""
payload = []
existing_project_names = [project_name.lower() for project_name in existing_project_names]
if updated_projects:
for project in updated_projects:
destination_id_of_project = project.mapping.first().destination.destination_id
payload.append({'id': project.source_id, 'name': project.value, 'code': destination_id_of_project, 'description': 'Project - {0}, Id - {1}'.format(project.value, destination_id_of_project), 'is_enabled': project.active})
else:
for project in projects:
if project.value.lower() not in existing_project_names:
payload.append({'name': project.value, 'code': project.destination_id, 'description': 'Project - {0}, Id - {1}'.format(project.value, project.destination_id), 'is_enabled': project.active})

return payload


def post_projects_in_batches(platform: PlatformConnector, workspace_id: int, destination_field: str):
existing_project_names = ExpenseAttribute.objects.filter(attribute_type='PROJECT', workspace_id=workspace_id).values_list('value', flat=True)
qbo_attributes_count = DestinationAttribute.objects.filter(attribute_type=destination_field, workspace_id=workspace_id).count()

page_size = 200
for offset in range(0, qbo_attributes_count, page_size):
limit = offset + page_size
paginated_qbo_attributes = DestinationAttribute.objects.filter(attribute_type=destination_field, workspace_id=workspace_id).order_by('value', 'id')[offset:limit]

paginated_qbo_attributes = remove_duplicates(paginated_qbo_attributes)

fyle_payload: List[Dict] = create_fyle_projects_payload(paginated_qbo_attributes, existing_project_names)
if fyle_payload:
platform.projects.post_bulk(fyle_payload)
platform.projects.sync()

Mapping.bulk_create_mappings(paginated_qbo_attributes, 'PROJECT', destination_field, workspace_id)

if destination_field == 'CUSTOMER':
project_ids_to_be_changed = disable_or_enable_expense_attributes('PROJECT', 'CUSTOMER', workspace_id)
if project_ids_to_be_changed:
expense_attributes = ExpenseAttribute.objects.filter(id__in=project_ids_to_be_changed)
fyle_payload: List[Dict] = create_fyle_projects_payload(projects=[], existing_project_names=[], updated_projects=expense_attributes)
platform.projects.post_bulk(fyle_payload)
platform.projects.sync()


@handle_import_exceptions(task_name='Auto Create Tax Code Mappings')
def auto_create_tax_codes_mappings(workspace_id: int):
"""
Expand All @@ -209,24 +161,6 @@ def auto_create_tax_codes_mappings(workspace_id: int):
upload_tax_groups_to_fyle(platform, workspace_id)


@handle_import_exceptions(task_name='Auto Create Project Mappings')
def auto_create_project_mappings(workspace_id: int):
"""
Create Project Mappings
:return: mappings
"""
fyle_credentials: FyleCredential = FyleCredential.objects.get(workspace_id=workspace_id)
platform = PlatformConnector(fyle_credentials)

platform.projects.sync()

mapping_setting = MappingSetting.objects.get(source_field='PROJECT', workspace_id=workspace_id)

sync_qbo_attribute(mapping_setting.destination_field, workspace_id)

post_projects_in_batches(platform, workspace_id, mapping_setting.destination_field)


def create_fyle_categories_payload(categories: List[DestinationAttribute], workspace_id: int, updated_categories: List[ExpenseAttribute] = None):
"""
Create Fyle Categories Payload from QBO Customer / Categories
Expand Down

0 comments on commit be7b007

Please sign in to comment.