Skip to content

Commit

Permalink
fix duplicated expense_groups (#653)
Browse files Browse the repository at this point in the history
* fix duplicated expense_groups

* fix expense_objects used
  • Loading branch information
Hrishabh17 authored and anishfyle committed Jul 23, 2024
1 parent a85abca commit acd341e
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def create_expense_groups_by_report_id_fund_source(
"""

expense_groups = []
filtered_corporate_credit_card_expense_groups = []
expense_group_settings = ExpenseGroupSettings.objects.get(
workspace_id=workspace_id
)
Expand Down Expand Up @@ -440,44 +441,45 @@ def create_expense_groups_by_report_id_fund_source(
filter(lambda expense: expense.fund_source == "CCC", expense_objects)
)

if (
general_settings.corporate_credit_card_expenses_object == 'CREDIT CARD PURCHASE' 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,
)
if corporate_credit_card_expenses:
if (
general_settings.corporate_credit_card_expenses_object == 'CREDIT CARD PURCHASE' and
expense_group_settings.split_expense_grouping == 'MULTIPLE_LINE_ITEM'
):
ccc_expenses_without_bank_transaction = [
expense for expense in corporate_credit_card_expenses
if not expense.bank_transaction_id
]

ccc_expenses_with_bank_transaction = [
expense for expense in corporate_credit_card_expenses
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 = [
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,
)
)
else:
filtered_corporate_credit_card_expense_groups = _group_expenses(
corporate_credit_card_expenses,
corporate_credit_card_expense_group_field,
workspace_id,
)

if (
general_settings.corporate_credit_card_expenses_object == "BILL"
Expand Down

0 comments on commit acd341e

Please sign in to comment.