Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug fix for support qbd (minor fix) #102

Merged
merged 10 commits into from
Aug 5, 2024
Merged
25 changes: 12 additions & 13 deletions apps/mappings/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,20 @@ def sync_projects(self, source_type: str):
'order': 'updated_at.desc'
}
projects_generator = self.platform.v1beta.admin.projects.list_all(query)
existing_projects = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)
existing_projects = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type).values_list('source_value', flat=True)

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,
'value': project['name'],
'source_id': project['id']
})

if project['name'] not in existing_projects:
anishfyle marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent fixed

source_attributes.append({
'attribute_type': source_type,
'value': project['name'],
'source_id': project['id']
})

if source_attributes:
QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id)
Expand All @@ -139,20 +138,20 @@ def sync_cost_center(self, source_type: str):
query = {
'order': 'updated_at.desc'
}

cost_center_generator = self.platform.v1beta.admin.cost_centers.list_all(query)
existing_cost_centers = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)
existing_cost_centers = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type).values_list('source_value', flat=True)

source_attributes = []

for cost_centers in cost_center_generator:
for cost_center in cost_centers.get('data'):
if cost_center not in existing_cost_centers:
if cost_center['name'] not in existing_cost_centers:
source_attributes.append({
'attribute_type': source_type,
'value': cost_center,
'source_id': cost_center
'value': cost_center['name'],
'source_id': cost_center['id']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name and id went missing, in concurrent prs, fixed this

})


if source_attributes:
QBDMapping.update_or_create_mapping_objects(source_attributes, self.workspace_id)
Loading