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: Updating the same QBD Mapping in case of name case change #74

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions apps/mappings/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ def get_qbd_mapping_stat(source_type: str, workspace_id: int):
"""
get qbd mapping stat will return the count of total mappings available and unmapped mappings
"""

total_attributes_count = QBDMapping.objects.filter(
workspace_id=workspace_id,
attribute_type = source_type).count()
attribute_type = source_type
Copy link

Choose a reason for hiding this comment

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

The filtering conditions have been correctly updated to accurately count total and unmapped attributes based on attribute_type and destination_value. However, for consistency and adherence to PEP 8 style guidelines, consider adjusting the spacing around the equals sign in the filter conditions.

- attribute_type = source_type
+ attribute_type=source_type
- destination_value__isnull=True
+ destination_value__isnull=True

Also applies to: 16-16


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
attribute_type = source_type
attribute_type=source_type

).count()

unmapped_attributes_count = QBDMapping.objects.filter(
workspace_id=workspace_id,
attribute_type = source_type,
destination_value__isnull=True).count()
destination_value__isnull=True
).count()

return {
'all_attributes_count': total_attributes_count,
'unmapped_attributes_count': unmapped_attributes_count
}
}
3 changes: 3 additions & 0 deletions apps/mappings/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def sync_corporate_card(self):
query = {
'order': 'updated_at.desc',
}

generator = self.platform.v1beta.admin.corporate_cards.list_all(query)

for items in generator:
card_attributes = []
unique_card_numbers = []
Expand All @@ -47,5 +49,6 @@ def sync_corporate_card(self):
'value': value,
'source_id': card['id'],
})

if len(card_attributes) > 0:
QBDMapping.update_or_create_mapping_objects(card_attributes, self.workspace_id)
18 changes: 18 additions & 0 deletions apps/mappings/migrations/0002_auto_20240318_0616.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2024-03-18 06:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mappings', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='qbdmapping',
name='source_id',
field=models.CharField(help_text='Fyle ID', max_length=255, unique=True),
),
]
10 changes: 5 additions & 5 deletions apps/mappings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class QBDMapping(models.Model):
id = models.AutoField(primary_key=True)
attribute_type = models.CharField(max_length=255, help_text='Type of expense attribute')
source_value = models.CharField(max_length=1000, help_text='Value of expense attribute')
source_id = models.CharField(max_length=255, help_text='Fyle ID')
source_id = models.CharField(max_length=255, help_text='Fyle ID', unique=True)
destination_value = models.CharField(max_length=1000,
null=True, blank=True, help_text='Value of destination attribute')
workspace = models.ForeignKey(Workspace, on_delete=models.PROTECT, help_text='Reference to Workspace model')
Expand All @@ -24,10 +24,10 @@ class Meta:
def update_or_create_mapping_objects(qbd_mapping_objects: List[Dict],workspace_id: int):
for qbd_mapping_object in qbd_mapping_objects:
QBDMapping.objects.update_or_create(
workspace_id= workspace_id,
source_value= qbd_mapping_object['value'],
attribute_type= qbd_mapping_object['attribute_type'],
workspace_id=workspace_id,
source_id=qbd_mapping_object['source_id'],
attribute_type=qbd_mapping_object['attribute_type'],
defaults={
'source_id': qbd_mapping_object['source_id'],
'source_value': qbd_mapping_object['value'],
}
)
Loading