Skip to content

Commit

Permalink
fix created_at, updated_at null constraint (#93)
Browse files Browse the repository at this point in the history
* fix created_at, updated_at null constraint

* fix created_at, updated_at null constraint

* remove the edit expenses

* uncomment test case for coverage
  • Loading branch information
Hrishabh17 committed Jul 15, 2024
1 parent 8996dfb commit 7a50e7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Meta:
db_table = 'expenses'

@staticmethod
def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: bool = True):
def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: bool = False):
"""
Bulk create expense objects
"""
Expand All @@ -81,6 +81,8 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
expense_data_to_append = {
'claim_number': expense['claim_number'],
'approved_at': expense['approved_at'],
'expense_created_at': expense['expense_created_at'],
'expense_updated_at': expense['expense_updated_at']
}

defaults = {
Expand All @@ -105,8 +107,6 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
'file_ids': expense['file_ids'],
'spent_at': expense['spent_at'],
'posted_at': expense['posted_at'],
'expense_created_at': expense['expense_created_at'],
'expense_updated_at': expense['expense_updated_at'],
'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']],
'verified_at': expense['verified_at'],
'custom_properties': expense['custom_properties'],
Expand Down
11 changes: 6 additions & 5 deletions apps/fyle/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def async_handle_webhook_callback(body: dict, workspace_id: int) -> None:
workspace = Workspace.objects.get(org_id=org_id)
async_task('apps.workspaces.tasks.run_import_export', workspace.id)

elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE':
org_id = body['data']['org_id']
logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data')))
assert_valid_request(workspace_id=workspace_id, org_id=org_id)
async_task('apps.fyle.tasks.update_non_exported_expenses', body['data'])
"""for allowing expense edit, uncomment the below code and relevant test if required in future"""
# elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE':
# org_id = body['data']['org_id']
# logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data')))
# assert_valid_request(workspace_id=workspace_id, org_id=org_id)
# async_task('apps.fyle.tasks.update_non_exported_expenses', body['data'])
4 changes: 2 additions & 2 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'name': 'Administration'
},
'cost_center_id': 23166,
'created_at': '2024-05-10T07:52:10.551260+00:00',
'created_at': None,
'creator_user_id': 'usVN2WTtPqE7',
'currency': 'USD',
'custom_fields': [
Expand Down Expand Up @@ -180,7 +180,7 @@
'tax_group': None,
'tax_group_id': None,
'travel_classes': [],
'updated_at': '2024-06-10T11:41:40.779611+00:00',
'updated_at': None,
'user': {
'email': '[email protected]',
'full_name': 'Theresa Brown',
Expand Down
15 changes: 8 additions & 7 deletions tests/test_fyle/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ def test_update_non_exported_expenses(db, create_temp_workspace, mocker, api_cli
except ValidationError as e:
assert e.detail[0] == 'Workspace mismatch'

url = reverse('webhook-callback', kwargs={'workspace_id': 1})
response = api_client.post(url, data=payload, format='json')
assert response.status_code == status.HTTP_200_OK

url = reverse('webhook-callback', kwargs={'workspace_id': 2})
response = api_client.post(url, data=payload, format='json')
assert response.status_code == status.HTTP_400_BAD_REQUEST
# uncomment this while using the webhook callback for edit expense
# url = reverse('webhook-callback', kwargs={'workspace_id': 1})
# response = api_client.post(url, data=payload, format='json')
# assert response.status_code == status.HTTP_200_OK

# url = reverse('webhook-callback', kwargs={'workspace_id': 2})
# response = api_client.post(url, data=payload, format='json')
# assert response.status_code == status.HTTP_400_BAD_REQUEST

0 comments on commit 7a50e7a

Please sign in to comment.