diff --git a/apps/mappings/queue.py b/apps/mappings/queue.py index c6912433..a813794d 100644 --- a/apps/mappings/queue.py +++ b/apps/mappings/queue.py @@ -136,6 +136,14 @@ def construct_tasks_and_chain_import_fields_to_fyle(workspace_id: int): FyleAttributeEnum.COST_CENTER, ] + if workspace_general_settings.import_tax_codes: + task_settings['import_tax'] = { + 'destination_field': 'TAX_CODE', + 'destination_sync_methods': [SYNC_METHODS['TAX_CODE']], + 'is_auto_sync_enabled': False, + 'is_3d_mapping': False + } + if mapping_settings: for mapping_setting in mapping_settings: if mapping_setting.source_field in ALLOWED_SOURCE_FIELDS or mapping_setting.is_custom: diff --git a/apps/mappings/schedules.py b/apps/mappings/schedules.py index 85b785a0..311fe30e 100644 --- a/apps/mappings/schedules.py +++ b/apps/mappings/schedules.py @@ -19,10 +19,10 @@ def new_schedule_or_delete_fyle_import_tasks( # short-hand notation, it returns True as soon as it encounters import_to_fyle as True task_to_be_scheduled = any(mapping_setting['import_to_fyle'] for mapping_setting in mapping_settings) - # if task_to_be_scheduled is True or import_customers(as Project) is True if ( task_to_be_scheduled or workspace_general_settings_instance.import_customers + or workspace_general_settings_instance.import_tax_codes ): Schedule.objects.update_or_create( func='apps.mappings.queue.construct_tasks_and_chain_import_fields_to_fyle', diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index 3ca8077e..af949d8f 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -286,78 +286,6 @@ def sync_xero_attributes(xero_attribute_type: str, workspace_id: int): xero_connection.sync_tracking_categories() -def upload_tax_groups_to_fyle( - platform_connection: PlatformConnector, workspace_id: int -): - existing_tax_codes_name = ExpenseAttribute.objects.filter( - attribute_type=FyleAttributeEnum.TAX_GROUP, workspace_id=workspace_id - ).values_list("value", flat=True) - - xero_attributes = DestinationAttribute.objects.filter( - attribute_type="TAX_CODE", workspace_id=workspace_id - ).order_by("value", "id") - - xero_attributes = remove_duplicates(xero_attributes) - - fyle_payload: List[Dict] = create_fyle_tax_group_payload( - xero_attributes, existing_tax_codes_name - ) - - if fyle_payload: - platform_connection.tax_groups.post_bulk(fyle_payload) - - platform_connection.tax_groups.sync() - Mapping.bulk_create_mappings(xero_attributes, FyleAttributeEnum.TAX_GROUP, "TAX_CODE", workspace_id) - - -def create_fyle_tax_group_payload( - xero_attributes: List[DestinationAttribute], existing_fyle_tax_groups: list -): - """ - Create Fyle tax Group Payload from Xero Objects - :param existing_fyle_tax_groups: Existing tax groups names - :param xero_attributes: Xero Objects - :return: Fyle tax Group Payload - """ - - existing_fyle_tax_groups = [ - tax_group.lower() for tax_group in existing_fyle_tax_groups - ] - - fyle_tax_group_payload = [] - for xero_attribute in xero_attributes: - if xero_attribute.value.lower() not in existing_fyle_tax_groups: - fyle_tax_group_payload.append( - { - "name": xero_attribute.value, - "is_enabled": True, - "percentage": round((xero_attribute.detail["tax_rate"] / 100), 2), - } - ) - - logger.info("| Importing Tax Groups to Fyle | Content: {{Fyle Payload count: {}}}".format(len(fyle_tax_group_payload))) - return fyle_tax_group_payload - - -@handle_import_exceptions(task_name="auto create tax codes_mappings") -def auto_create_tax_codes_mappings(workspace_id: int): - """ - Create Tax Codes Mappings - :return: None - """ - - fyle_credentials: FyleCredential = FyleCredential.objects.get( - workspace_id=workspace_id - ) - - platform = PlatformConnector(fyle_credentials=fyle_credentials) - platform.tax_groups.sync() - - sync_xero_attributes("TAX_CODE", workspace_id) - - upload_tax_groups_to_fyle(platform, workspace_id) - - def auto_create_suppliers_as_merchants(workspace_id): fyle_credentials: FyleCredential = FyleCredential.objects.get( workspace_id=workspace_id diff --git a/apps/workspaces/apis/import_settings/triggers.py b/apps/workspaces/apis/import_settings/triggers.py index b9d16314..4b3f9eea 100644 --- a/apps/workspaces/apis/import_settings/triggers.py +++ b/apps/workspaces/apis/import_settings/triggers.py @@ -3,10 +3,6 @@ from django.db.models import Q from fyle_accounting_mappings.models import MappingSetting -from apps.mappings.helpers import schedule_or_delete_fyle_import_tasks -from apps.mappings.queue import ( - schedule_tax_groups_creation -) from apps.mappings.helpers import schedule_or_delete_fyle_import_tasks from apps.workspaces.models import WorkspaceGeneralSettings from apps.mappings.schedules import new_schedule_or_delete_fyle_import_tasks @@ -33,12 +29,6 @@ def post_save_workspace_general_settings( """ Post save action for workspace general settings """ - # This will take care of auto creating tax mappings - schedule_tax_groups_creation( - import_tax_codes=self.__workspace_general_settings.get("import_tax_codes"), - workspace_id=self.__workspace_id, - ) - if not self.__workspace_general_settings.get("import_customers"): MappingSetting.objects.filter( workspace_id=self.__workspace_id, diff --git a/apps/xero/actions.py b/apps/xero/actions.py index d356381f..b61a4aaa 100644 --- a/apps/xero/actions.py +++ b/apps/xero/actions.py @@ -79,16 +79,6 @@ def refersh_xero_dimension(workspace_id): 'cluster': 'import' } ) - - elif mapping_setting.is_custom: - # run async_auto_create_custom_field_mappings - chain.append( - "apps.mappings.tasks.async_auto_create_custom_field_mappings", - int(workspace_id), - q_options={ - 'cluster': 'import' - } - ) elif workspace_general_settings.import_suppliers_as_merchants: # run auto_create_suppliers_as_merchant chain.append(