Skip to content

Commit

Permalink
logic fixed for date
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Nov 30, 2023
1 parent 7a3bef9 commit e2a981e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion apps/accounting_exports/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import List

from django.contrib.postgres.aggregates import ArrayAgg
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e2a981e

Please sign in to comment.