From ef6e76e224f3228f6b7fab32a61dd8388677e1e1 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Mon, 22 Jul 2024 16:16:12 +0530 Subject: [PATCH 1/2] fix duplicated expense_groups --- apps/fyle/models.py | 70 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/apps/fyle/models.py b/apps/fyle/models.py index 5df40b60..8583f833 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -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 ) @@ -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 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 = [ + 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" From faa557f79a070ad75d6f37d3ae1381d25b212ccf Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Mon, 22 Jul 2024 16:31:31 +0530 Subject: [PATCH 2/2] fix expense_objects used --- apps/fyle/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/fyle/models.py b/apps/fyle/models.py index 8583f833..1420c9dd 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -447,12 +447,12 @@ def create_expense_groups_by_report_id_fund_source( expense_group_settings.split_expense_grouping == 'MULTIPLE_LINE_ITEM' ): ccc_expenses_without_bank_transaction = [ - expense for expense in expense_objects + expense for expense in corporate_credit_card_expenses if not expense.bank_transaction_id ] ccc_expenses_with_bank_transaction = [ - expense for expense in expense_objects + expense for expense in corporate_credit_card_expenses if expense.bank_transaction_id ]