Skip to content

Commit

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

* fix expense fetching

* fix null refresh token
  • Loading branch information
Hrishabh17 committed Jul 15, 2024
1 parent 2cb05b7 commit 1f22139
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
'claim_number': expense['claim_number'],
'report_title': expense['report_title'],
'approved_at': expense['approved_at'],
'payment_number': expense['payment_number']
'payment_number': expense['payment_number'],
'expense_created_at': expense['expense_created_at'],
'expense_updated_at': expense['expense_updated_at']
}

defaults = {
Expand All @@ -142,8 +144,6 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
'report_id': expense['report_id'],
'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
8 changes: 6 additions & 2 deletions apps/fyle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ImportFyleAttributesSerializer,
)
from apps.accounting_exports.helpers import ExpenseSearchFilter
from apps.workspaces.models import ExportSetting

from ms_business_central_api.utils import LookupFieldMixin

Expand Down Expand Up @@ -97,9 +98,12 @@ def post(self, request, *args, **kwargs):
"""
Post expense groups creation
"""
export_settings = ExportSetting.objects.get(workspace_id=kwargs['workspace_id'])

queue_import_reimbursable_expenses(kwargs['workspace_id'], synchronous=True)
queue_import_credit_card_expenses(kwargs['workspace_id'], synchronous=True)
if export_settings.reimbursable_expenses_export_type:
queue_import_reimbursable_expenses(kwargs['workspace_id'], synchronous=True)
if export_settings.credit_card_expense_export_type:
queue_import_credit_card_expenses(kwargs['workspace_id'], synchronous=True)

return Response(
status=status.HTTP_200_OK
Expand Down
2 changes: 1 addition & 1 deletion apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

def async_update_fyle_credentials(fyle_org_id: str, refresh_token: str):
fyle_credentials = FyleCredential.objects.filter(workspace__org_id=fyle_org_id).first()
if fyle_credentials:
if fyle_credentials and refresh_token:
fyle_credentials.refresh_token = refresh_token
fyle_credentials.save()

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 @@ -179,7 +179,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',
Expand Down

0 comments on commit 1f22139

Please sign in to comment.