From 2e6e07e23dcc0eefa5e264214b017fea67fedcae Mon Sep 17 00:00:00 2001 From: anishfyle Date: Wed, 24 Jul 2024 16:04:23 +0530 Subject: [PATCH] lint fix --- apps/mappings/connector.py | 200 ++++++++++++++++----------------- tests/test_mapping/fixtures.py | 2 +- 2 files changed, 101 insertions(+), 101 deletions(-) diff --git a/apps/mappings/connector.py b/apps/mappings/connector.py index b85ee5b..2a6990c 100644 --- a/apps/mappings/connector.py +++ b/apps/mappings/connector.py @@ -53,104 +53,104 @@ def sync_corporate_card(self): if len(card_attributes) > 0: QBDMapping.update_or_create_mapping_objects(card_attributes, self.workspace_id) -def sync_custom_field(self, source_type: str, field_mapping: FieldMapping, sync_custom_field_options: bool = False): - """ - Sync custom fields that are mapped to the Item in the FieldMapping - :source_type: The Custom Field Items is mapped to - :field_mapping: FieldMapping instance - :sync_custom_field_options: bool, when set to true, we create the QBDMapping - else only update the values of custom_fields in field_mapping table - """ - - query = { - 'order': 'updated_at.desc', - 'is_custom': 'eq.true', - 'type': 'eq.SELECT', - 'is_enabled': 'eq.true' - } - workspace_id = self.context['request'].parser_context.get('kwargs').get('workspace_id') - custom_fields = self.platform.v1beta.admin.expense_custom_fields.list_all(query) - query = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type) - existing_source_attributes = query.values_list('value', flat=True) - - distinct_custom_fields = [] - source_values = [] - - for custom_field in custom_fields: - distinct_custom_fields.append(custom_field['field_name']) - if source_type == custom_field['field_name']: - source_values.extend(custom_field['options']) - - if distinct_custom_fields: - field_mapping.custom_fields = distinct_custom_fields - field_mapping.save() - - if sync_custom_field_options: - source_attributes = [] - for source_value in source_values: - if source_value not in existing_source_attributes: - source_attributes.append({ - 'attribute_type': source_type, - 'source_value': source_value, - 'source_id': source_value - }) - if source_attributes: - QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id) - - -def sync_projects(self, source_type: str): - """ - Sync PROJECT as Item - """ - - query = { - 'order': 'updated_at.desc' - } - workspace_id = self.context['request'].parser_context.get('kwargs').get('workspace_id') - projects_generator = self.platform.v1beta.admin.projects.list_all(query) - existing_projects = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type) - - source_attributes = [] - - for projects in projects_generator: - for project in projects.get('data'): - if project['sub_project']: - project['name'] = '{0} / {1}'.format(project['name'], project['sub_project']) - if project['name'] not in existing_projects: - source_attributes.append({ + def sync_custom_field(self, source_type: str, field_mapping: FieldMapping, sync_custom_field_options: bool = False): + """ + Sync custom fields that are mapped to the Item in the FieldMapping + :source_type: The Custom Field Items is mapped to + :field_mapping: FieldMapping instance + :sync_custom_field_options: bool, when set to true, we create the QBDMapping + else only update the values of custom_fields in field_mapping table + """ + + query = { + 'order': 'updated_at.desc', + 'is_custom': 'eq.true', + 'type': 'eq.SELECT', + 'is_enabled': 'eq.true' + } + workspace_id = self.context['request'].parser_context.get('kwargs').get('workspace_id') + custom_fields = self.platform.v1beta.admin.expense_custom_fields.list_all(query) + query = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type) + existing_source_attributes = query.values_list('value', flat=True) + + distinct_custom_fields = [] + source_values = [] + + for custom_field in custom_fields: + distinct_custom_fields.append(custom_field['field_name']) + if source_type == custom_field['field_name']: + source_values.extend(custom_field['options']) + + if distinct_custom_fields: + field_mapping.custom_fields = distinct_custom_fields + field_mapping.save() + + if sync_custom_field_options: + source_attributes = [] + for source_value in source_values: + if source_value not in existing_source_attributes: + source_attributes.append({ 'attribute_type': source_type, - 'source_value': project['name'], - 'source_id': project['id'] - }) - - - if source_attributes: - QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id) - - -def sync_cost_center(self, source_type: str): - """ - Sync PROJECT as Item - """ - - query = { - 'order': 'updated_at.desc' - } - workspace_id = self.context['request'].parser_context.get('kwargs').get('workspace_id') - cost_center_generator = self.platform.v1beta.admin.cost_centers.list_all(query) - existing_cost_centers = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type) - - source_attributes = [] - - for cost_centers in cost_center_generator: - for cost_center in cost_centers.get('data'): - if cost_center['name'] not in existing_cost_centers: - source_attributes.append({ - 'attribute_type': source_type, - 'source_value': cost_center['name'], - 'source_id': cost_center['id'] - }) - - - if source_attributes: - QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id) \ No newline at end of file + 'source_value': source_value, + 'source_id': source_value + }) + if source_attributes: + QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id) + + + def sync_projects(self, source_type: str): + """ + Sync PROJECT as Item + """ + + query = { + 'order': 'updated_at.desc' + } + workspace_id = self.context['request'].parser_context.get('kwargs').get('workspace_id') + projects_generator = self.platform.v1beta.admin.projects.list_all(query) + existing_projects = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type) + + source_attributes = [] + + for projects in projects_generator: + for project in projects.get('data'): + if project['sub_project']: + project['name'] = '{0} / {1}'.format(project['name'], project['sub_project']) + if project['name'] not in existing_projects: + source_attributes.append({ + 'attribute_type': source_type, + 'source_value': project['name'], + 'source_id': project['id'] + }) + + + if source_attributes: + QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id) + + + def sync_cost_center(self, source_type: str): + """ + Sync PROJECT as Item + """ + + query = { + 'order': 'updated_at.desc' + } + workspace_id = self.context['request'].parser_context.get('kwargs').get('workspace_id') + cost_center_generator = self.platform.v1beta.admin.cost_centers.list_all(query) + existing_cost_centers = QBDMapping.objects.filter(workspace_id=workspace_id, attribute_type=source_type) + + source_attributes = [] + + for cost_centers in cost_center_generator: + for cost_center in cost_centers.get('data'): + if cost_center['name'] not in existing_cost_centers: + source_attributes.append({ + 'attribute_type': source_type, + 'source_value': cost_center['name'], + 'source_id': cost_center['id'] + }) + + + if source_attributes: + QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id) \ No newline at end of file diff --git a/tests/test_mapping/fixtures.py b/tests/test_mapping/fixtures.py index f66a850..cee79c9 100644 --- a/tests/test_mapping/fixtures.py +++ b/tests/test_mapping/fixtures.py @@ -138,7 +138,7 @@ }, ] }, - 'get_qbd_ccc_mapping_project': { + 'get_qbd_ccc_mapping_project': { "count": 2, "next": "http://localhost:8008/api/workspaces/1/qbd_mappings/?attribute_type=ITEMS", "previous": '',