diff --git a/apps/accounting_exports/models.py b/apps/accounting_exports/models.py index 34a237e..9e5f552 100644 --- a/apps/accounting_exports/models.py +++ b/apps/accounting_exports/models.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import List from django.contrib.postgres.aggregates import ArrayAgg @@ -33,6 +34,10 @@ ('AUTO', 'AUTO') ) +ALLOWED_FORM_INPUT = { + 'export_date_type': ['current_date', 'approved_at', 'verified_at', 'last_spent_at', 'posted_at'] +} + def _group_expenses(expenses: List[Expense], export_setting: ExportSetting, fund_source: str): """ @@ -129,10 +134,16 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w # Store expense IDs and remove unnecessary keys expense_ids = accounting_export['expense_ids'] - accounting_export[date_field] = accounting_export[date_field].strftime('%Y-%m-%dT%H:%M:%S') accounting_export.pop('total') accounting_export.pop('expense_ids') + for key in accounting_export: + if key in ALLOWED_FORM_INPUT['export_date_type']: + if accounting_export[key]: + accounting_export[key] = accounting_export[key].strftime('%Y-%m-%dT%H:%M:%S') + else: + accounting_export[key] = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') + # Create an AccountingExport object for the expense group accounting_export_instance = AccountingExport.objects.create( workspace_id=workspace_id,