Skip to content

Commit

Permalink
fix: added check for empty item_type get_item_and_account_name (#99)
Browse files Browse the repository at this point in the history
* fix: added check for empty item_type get_item_and_account_name

* fix for async_task('apps.fyle.actions.sync_fyle_dimensions', workspace.id)

* custom field query

* added mock

* pr comment

* Update serializers.py

* fix sync bug

---------

Co-authored-by: Hrishabh Tiwari <[email protected]>
Co-authored-by: Hrishabh Tiwari <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent facd7c5 commit 3a0c741
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions apps/mappings/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def sync_custom_field(
"""

query = {
'order': 'updated_at.desc',
'is_custom': 'eq.true',
'type': 'eq.SELECT',
'is_enabled': 'eq.true'
'order': 'updated_at.desc',
'is_custom': 'eq.true',
'type': 'eq.SELECT',
'is_enabled': 'eq.true'
}
custom_field_gen = field_mapping.custom_fields
custom_field_gen = self.platform.v1beta.admin.expense_fields.list_all(query)
if source_type:
query = QBDMapping.objects.filter(workspace_id=self.workspace_id, attribute_type=source_type)
existing_source_attributes = query.values_list('source_value', flat=True)
Expand All @@ -87,7 +87,7 @@ def sync_custom_field(
if source_type and source_type == custom_field['field_name']:
source_values.extend(custom_field['options'])

if distinct_custom_fields and sync_expense_custom_field_names:
if distinct_custom_fields:
field_mapping.custom_fields = distinct_custom_fields
field_mapping.save()

Expand Down
6 changes: 6 additions & 0 deletions apps/qbd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

def get_item_and_account_name(field_mapping: FieldMapping, expense: Expense, workspace_id: int):
item_type = field_mapping.item_type

# Check if item_type is not None before proceeding
if item_type is None:
# Handle the case where item_type is None, e.g., return a default value or raise a custom error
return '', expense.category

expense_item = None
expense_category = expense.category

Expand Down
4 changes: 3 additions & 1 deletion apps/workspaces/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def create(self, validated_data):
FieldMapping.objects.update_or_create(
workspace=workspace
)

return workspace


Expand Down Expand Up @@ -117,6 +117,8 @@ def create(self, validated_data):
if workspace.onboarding_state == 'EXPORT_SETTINGS':
workspace.onboarding_state = 'FIELD_MAPPINGS'
workspace.save()

async_task('apps.fyle.actions.sync_fyle_dimensions', workspace.id)

return export_settings

Expand Down
3 changes: 3 additions & 0 deletions tests/test_fyle/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def test_sync_fyle_dimension_view(api_client, test_connection, mocker):
'fyle.platform.apis.v1beta.admin.corporate_cards.list_all',
return_value=fixture['credit_card_sdk']
)
mocker.patch(
'fyle.platform.apis.v1beta.admin.expense_fields.list_all'
)
url = reverse(
'workspaces'
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mapping/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_sync_cost_center(create_temp_workspace, add_fyle_credentials, mocker):
assert mapping.source_value == cost_center


@pytest.mark.django_db(databases=['default'])
@pytest.mark.django_db(databases=['default'], transaction=True)
def test_sync_custom_field(mocker, api_client, test_connection):
access_token = test_connection.access_token

Expand Down Expand Up @@ -97,7 +97,7 @@ def test_sync_custom_field(mocker, api_client, test_connection):

# Check if custom fields are updated in FieldMapping
field_mapping.refresh_from_db()
assert field_mapping.custom_fields == ['field1']
assert field_mapping.custom_fields == ['field1', 'field2']

# Check if QBDMapping objects are created
qbd_mappings = QBDMapping.objects.filter(workspace_id=1, attribute_type='field1')
Expand Down

0 comments on commit 3a0c741

Please sign in to comment.