Skip to content

Commit

Permalink
Fix: Updating the same QBD Mapping in case of name case change
Browse files Browse the repository at this point in the history
  • Loading branch information
Shwetabhk committed Mar 18, 2024
1 parent cf87bae commit cbdece0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
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
).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'],
}
)

0 comments on commit cbdece0

Please sign in to comment.