Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anishfyle committed Jul 24, 2024
1 parent de6e99a commit 2e6e07e
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 101 deletions.
200 changes: 100 additions & 100 deletions apps/mappings/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'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)
2 changes: 1 addition & 1 deletion tests/test_mapping/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": '',
Expand Down

0 comments on commit 2e6e07e

Please sign in to comment.