Skip to content

Commit

Permalink
Fix: journal entry expense grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Dec 14, 2023
1 parent dd40f98 commit d5eed0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def filter_expense_groups(expense_groups, expenses: Expense, expenses_object, ex
filtered_expenses = filter_negative_expenses(filtered_expenses)

# Export type => Journal Entry, Expense Report and Group By => Expense
elif (expenses_object == 'EXPENSE_REPORT' and 'expense_id' in expense_group_fields) or expenses_object == 'JOURNAL_ENTRY':
elif (expenses_object == 'EXPENSE_REPORT' and 'expense_id' in expense_group_fields):
filtered_expenses = filter_negative_expenses(filtered_expenses)

filtered_expense_ids = [item.id for item in filtered_expenses]
Expand Down
29 changes: 29 additions & 0 deletions tests/test_fyle/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,35 @@ def test_create_expense_groups_by_report_id_fund_source_test_7(db):
expense_group_settings.save()


expense_groups = _group_expenses(expense_objects, ['employee_email','expense_id','fund_source','spent_at'], 1)
assert expense_groups[0]['total'] == 1

ExpenseGroup.create_expense_groups_by_report_id_fund_source(expense_objects, configuration, workspace_id)
expense_groups = ExpenseGroup.objects.filter(description__contains={'expense_id': 'tx4ziVSAyIsy'}).count()
assert expense_groups == 1
expense_groups = ExpenseGroup.objects.filter(description__contains={'expense_id': 'tx4ziVSAyIst'}).count()
assert expense_groups == 1

def test_create_expense_groups_by_report_id_fund_source_test_8(db):
"""
Group by expense
1 negative expenses
"""
workspace_id = 1
payload = data['positive_expenses']
payload[0]['amount'] = -50

configuration = Configuration.objects.get(workspace_id=workspace_id)
configuration.reimbursable_expenses_object = 'JOURNAL_ENTRY'
configuration.save()
expense_objects = Expense.create_expense_objects(payload, workspace_id)

expense_group_settings = ExpenseGroupSettings.objects.get(workspace_id=workspace_id)
expense_group_settings.reimbursable_export_date_type = 'spent_at'
expense_group_settings.reimbursable_expense_group_fields = ["employee_email", "expense_id", "fund_source", "spent_at" ]
expense_group_settings.save()


expense_groups = _group_expenses(expense_objects, ['employee_email','expense_id','fund_source','spent_at'], 1)
assert expense_groups[0]['total'] == 1

Expand Down

0 comments on commit d5eed0c

Please sign in to comment.