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: added check for empty item_type get_item_and_account_name #99

Merged
merged 7 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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'
)
anishfyle marked this conversation as resolved.
Show resolved Hide resolved
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
Loading