From 757e2992dca2665798fad1a2e9888333aab0839f Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:17:30 +0530 Subject: [PATCH] fix created_at, updated_at null constraint (#93) * fix created_at, updated_at null constraint * fix created_at, updated_at null constraint * remove the edit expenses * uncomment test case for coverage --- apps/fyle/models.py | 6 +++--- apps/fyle/queue.py | 11 ++++++----- tests/test_fyle/fixtures.py | 4 ++-- tests/test_fyle/test_tasks.py | 15 ++++++++------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/apps/fyle/models.py b/apps/fyle/models.py index fd6d45a..fbdc50f 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -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 """ @@ -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 = { @@ -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'], diff --git a/apps/fyle/queue.py b/apps/fyle/queue.py index 189e741..817176b 100644 --- a/apps/fyle/queue.py +++ b/apps/fyle/queue.py @@ -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']) diff --git a/tests/test_fyle/fixtures.py b/tests/test_fyle/fixtures.py index e5b883f..0be089e 100644 --- a/tests/test_fyle/fixtures.py +++ b/tests/test_fyle/fixtures.py @@ -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': [ @@ -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': 'admin1@fyleforimporrttest.in', 'full_name': 'Theresa Brown', diff --git a/tests/test_fyle/test_tasks.py b/tests/test_fyle/test_tasks.py index 15c7cc5..c770d65 100644 --- a/tests/test_fyle/test_tasks.py +++ b/tests/test_fyle/test_tasks.py @@ -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