Skip to content

Commit

Permalink
fix created_at, updated_at null constraint (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrishabh17 committed Jul 15, 2024
1 parent 947d3d6 commit 3bd040a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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"]
],
Expand All @@ -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
Expand Down
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

0 comments on commit 3bd040a

Please sign in to comment.