From 3bd040a71617f074b44ce9df8d071febc80dea8c Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:53:25 +0530 Subject: [PATCH] fix created_at, updated_at null constraint (#386) --- apps/fyle/models.py | 11 ++++++----- tests/test_fyle/fixtures.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/fyle/models.py b/apps/fyle/models.py index f560116e..884e9f96 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -165,13 +165,16 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: for expense in expenses: cutoff_date = _format_date("2021-08-01T00:00:00.000Z") - expense_created_at = _format_date(expense["expense_created_at"]) + if expense["expense_created_at"]: + expense_created_at = _format_date(expense["expense_created_at"]) expense_data_to_append = None if not skip_update: expense_data_to_append = { 'claim_number': expense['claim_number'], - 'approved_at': expense['approved_at'] + 'approved_at': expense['approved_at'], + "expense_created_at": expense["expense_created_at"], + "expense_updated_at": expense["expense_updated_at"] } defaults = { @@ -198,8 +201,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"] ], @@ -218,7 +219,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: if expense_data_to_append: defaults.update(expense_data_to_append) - if expense_created_at > cutoff_date: + if skip_update or expense_created_at > cutoff_date: expense_object, _ = Expense.objects.update_or_create( expense_id=expense["id"], defaults=defaults diff --git a/tests/test_fyle/fixtures.py b/tests/test_fyle/fixtures.py index a78d4f87..c26670cf 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',