Skip to content

Commit

Permalink
Handle Split Expenses Grouping (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
anishfyle authored Jul 10, 2024
1 parent 8a540f6 commit a0bb3d2
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,48 @@ def create_expense_groups_by_report_id_fund_source(expense_objects: List[Expense

corporate_credit_card_expense_group_field = expense_group_settings.corporate_credit_card_expense_group_fields
corporate_credit_card_expenses = list(filter(lambda expense: expense.fund_source == 'CCC', expense_objects))
corporate_credit_card_expense_groups = _group_expenses(
corporate_credit_card_expenses, corporate_credit_card_expense_group_field, workspace_id)

if (
configuration.corporate_credit_card_expenses_object == 'CHARGE_CARD_TRANSACTION' and
expense_group_settings.split_expense_grouping == 'MULTIPLE_LINE_ITEM'
):
ccc_expenses_without_bank_transaction = [
expense for expense in expense_objects
if not expense.bank_transaction_id
]

ccc_expenses_with_bank_transaction = [
expense for expense in expense_objects
if expense.bank_transaction_id
]

filtered_corporate_credit_card_expense_groups = _group_expenses(
ccc_expenses_without_bank_transaction,
corporate_credit_card_expense_group_field,
workspace_id,
)

corporate_credit_card_expense_group_field = [
field for field in corporate_credit_card_expense_group_field
if field not in {'expense_number', 'expense_id'}
]
corporate_credit_card_expense_group_field.append('bank_transaction_id')
filtered_corporate_credit_card_expense_groups.extend(
_group_expenses(
ccc_expenses_with_bank_transaction,
corporate_credit_card_expense_group_field,
workspace_id,
)
)
else:
filtered_corporate_credit_card_expense_groups = _group_expenses(
corporate_credit_card_expenses,
corporate_credit_card_expense_group_field,
workspace_id,
)

filtered_corporate_credit_card_expense_groups = filter_expense_groups(
corporate_credit_card_expense_groups, corporate_credit_card_expenses, configuration.corporate_credit_card_expenses_object, corporate_credit_card_expense_group_field
filtered_corporate_credit_card_expense_groups, corporate_credit_card_expenses, configuration.corporate_credit_card_expenses_object, corporate_credit_card_expense_group_field
)

expense_groups.extend(filtered_corporate_credit_card_expense_groups)
Expand Down

0 comments on commit a0bb3d2

Please sign in to comment.