Skip to content

Commit 3472149

Browse files
authored
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
1 parent e9c0c92 commit 3472149

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

apps/fyle/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Meta:
6969
db_table = 'expenses'
7070

7171
@staticmethod
72-
def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: bool = True):
72+
def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: bool = False):
7373
"""
7474
Bulk create expense objects
7575
"""
@@ -81,6 +81,8 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
8181
expense_data_to_append = {
8282
'claim_number': expense['claim_number'],
8383
'approved_at': expense['approved_at'],
84+
'expense_created_at': expense['expense_created_at'],
85+
'expense_updated_at': expense['expense_updated_at']
8486
}
8587

8688
defaults = {
@@ -105,8 +107,6 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
105107
'file_ids': expense['file_ids'],
106108
'spent_at': expense['spent_at'],
107109
'posted_at': expense['posted_at'],
108-
'expense_created_at': expense['expense_created_at'],
109-
'expense_updated_at': expense['expense_updated_at'],
110110
'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']],
111111
'verified_at': expense['verified_at'],
112112
'custom_properties': expense['custom_properties'],

apps/fyle/queue.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ def async_handle_webhook_callback(body: dict, workspace_id: int) -> None:
7777
workspace = Workspace.objects.get(org_id=org_id)
7878
async_task('apps.workspaces.tasks.run_import_export', workspace.id)
7979

80-
elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE':
81-
org_id = body['data']['org_id']
82-
logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data')))
83-
assert_valid_request(workspace_id=workspace_id, org_id=org_id)
84-
async_task('apps.fyle.tasks.update_non_exported_expenses', body['data'])
80+
"""for allowing expense edit, uncomment the below code and relevant test if required in future"""
81+
# elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE':
82+
# org_id = body['data']['org_id']
83+
# logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data')))
84+
# assert_valid_request(workspace_id=workspace_id, org_id=org_id)
85+
# async_task('apps.fyle.tasks.update_non_exported_expenses', body['data'])

tests/test_fyle/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
'name': 'Administration'
4444
},
4545
'cost_center_id': 23166,
46-
'created_at': '2024-05-10T07:52:10.551260+00:00',
46+
'created_at': None,
4747
'creator_user_id': 'usVN2WTtPqE7',
4848
'currency': 'USD',
4949
'custom_fields': [
@@ -180,7 +180,7 @@
180180
'tax_group': None,
181181
'tax_group_id': None,
182182
'travel_classes': [],
183-
'updated_at': '2024-06-10T11:41:40.779611+00:00',
183+
'updated_at': None,
184184
'user': {
185185
'email': 'admin1@fyleforimporrttest.in',
186186
'full_name': 'Theresa Brown',

tests/test_fyle/test_tasks.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,11 @@ def test_update_non_exported_expenses(db, create_temp_workspace, mocker, api_cli
299299
except ValidationError as e:
300300
assert e.detail[0] == 'Workspace mismatch'
301301

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

0 commit comments

Comments
 (0)