From 4a4d4618dd08784c7f699d4f8e80b2b495dcfb2d Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Fri, 17 Nov 2023 11:42:44 +0530 Subject: [PATCH 1/6] fix: Making Unspecified always active --- apps/mappings/tasks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index 59d31f07..fc4ff592 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -238,6 +238,9 @@ def create_fyle_categories_payload(categories: List[DestinationAttribute], works if updated_categories: for category in updated_categories: + if category.value == 'Unspecified': + category.active = True + destination_id_of_category = category.mapping.first().destination.destination_id payload.append({'id': category.source_id, 'name': category.value, 'code': destination_id_of_category, 'is_enabled': category.active}) else: From 249b94ba3578930d42d48f08d50ca9c1e22a6549 Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Fri, 17 Nov 2023 11:50:11 +0530 Subject: [PATCH 2/6] increasing coverage --- tests/test_mappings/test_tasks.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_mappings/test_tasks.py b/tests/test_mappings/test_tasks.py index 9759d6c9..c769a52a 100644 --- a/tests/test_mappings/test_tasks.py +++ b/tests/test_mappings/test_tasks.py @@ -219,7 +219,15 @@ def test_create_fyle_category_payload(db): qbo_attributes = remove_duplicates(qbo_attributes) - fyle_category_payload = create_fyle_categories_payload(qbo_attributes, 2) + fyle_category_payload = create_fyle_categories_payload(qbo_attributes, 2, [ + ExpenseAttribute( + attribute_type='CATEGORY', + value='Unspecified', + source_id='Unspecified', + display_name='Category', + workspace_id=1 + ) + ]) assert dict_compare_keys(fyle_category_payload[0], data['fyle_category_payload'][0]) == [], 'category upload api return diffs in keys' From 14136e5b27edb90f04702f70a7382ed2f49bcec3 Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Fri, 17 Nov 2023 11:51:20 +0530 Subject: [PATCH 3/6] Adding code commit --- apps/mappings/tasks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index fc4ff592..a56c8635 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -239,6 +239,8 @@ def create_fyle_categories_payload(categories: List[DestinationAttribute], works if updated_categories: for category in updated_categories: if category.value == 'Unspecified': + # Unspecified category should always be enabled + # If it is disabled, then enable it category.active = True destination_id_of_category = category.mapping.first().destination.destination_id From 5e12091cb7d32d310ca3f11ab52735fb6e63789a Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Fri, 17 Nov 2023 11:57:04 +0530 Subject: [PATCH 4/6] doing it differently --- apps/mappings/tasks.py | 14 ++++++++------ tests/test_mappings/test_tasks.py | 10 +--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index a56c8635..8f451bb3 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -238,13 +238,15 @@ def create_fyle_categories_payload(categories: List[DestinationAttribute], works if updated_categories: for category in updated_categories: - if category.value == 'Unspecified': - # Unspecified category should always be enabled - # If it is disabled, then enable it - category.active = True - destination_id_of_category = category.mapping.first().destination.destination_id - payload.append({'id': category.source_id, 'name': category.value, 'code': destination_id_of_category, 'is_enabled': category.active}) + payload.append({ + 'id': category.source_id, + 'name': category.value, + 'code': destination_id_of_category, + # Always keep Unspecified category enabled + 'is_enabled': category.active if category.value != 'Unspecified' else True, + } + ) else: existing_category_names = ExpenseAttribute.objects.filter(attribute_type='CATEGORY', workspace_id=workspace_id).values_list('value', flat=True) diff --git a/tests/test_mappings/test_tasks.py b/tests/test_mappings/test_tasks.py index c769a52a..9759d6c9 100644 --- a/tests/test_mappings/test_tasks.py +++ b/tests/test_mappings/test_tasks.py @@ -219,15 +219,7 @@ def test_create_fyle_category_payload(db): qbo_attributes = remove_duplicates(qbo_attributes) - fyle_category_payload = create_fyle_categories_payload(qbo_attributes, 2, [ - ExpenseAttribute( - attribute_type='CATEGORY', - value='Unspecified', - source_id='Unspecified', - display_name='Category', - workspace_id=1 - ) - ]) + fyle_category_payload = create_fyle_categories_payload(qbo_attributes, 2) assert dict_compare_keys(fyle_category_payload[0], data['fyle_category_payload'][0]) == [], 'category upload api return diffs in keys' From 3c393bce6a9dc771cb150dbe4dd9fcdcae840077 Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Fri, 17 Nov 2023 11:58:27 +0530 Subject: [PATCH 5/6] Removing unnecessary comma --- apps/mappings/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index 8f451bb3..5d7f44d7 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -244,7 +244,7 @@ def create_fyle_categories_payload(categories: List[DestinationAttribute], works 'name': category.value, 'code': destination_id_of_category, # Always keep Unspecified category enabled - 'is_enabled': category.active if category.value != 'Unspecified' else True, + 'is_enabled': category.active if category.value != 'Unspecified' else True } ) else: From cfb47b1fb65dc75163e4d73cda65065f44936055 Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Fri, 17 Nov 2023 12:01:05 +0530 Subject: [PATCH 6/6] Fix linting errors --- apps/mappings/tasks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index 5d7f44d7..4765858d 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -245,8 +245,7 @@ def create_fyle_categories_payload(categories: List[DestinationAttribute], works 'code': destination_id_of_category, # Always keep Unspecified category enabled 'is_enabled': category.active if category.value != 'Unspecified' else True - } - ) + }) else: existing_category_names = ExpenseAttribute.objects.filter(attribute_type='CATEGORY', workspace_id=workspace_id).values_list('value', flat=True)