From 30252d4c266bc4f57bcb64df4e1791b0fe907991 Mon Sep 17 00:00:00 2001 From: Ashwin Thanaraj <37061471+ashwin1111@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:33:51 +0530 Subject: [PATCH] Fix export mode for Exports from Fyle | Export only selected reports (#516) * Fix export mode for Exports from Fyle * Export only selected reports --- apps/fyle/tasks.py | 7 ++++++- apps/workspaces/actions.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index aee329e2..d2db52e5 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -237,7 +237,12 @@ def import_and_export_expenses(report_id: str, org_id: str) -> None: group_expenses_and_save(expenses, task_log, workspace) - export_to_qbo(workspace.id, 'AUTO') + # Export only selected expense groups + expense_ids = Expense.objects.filter(report_id=report_id, org_id=org_id).values_list('id', flat=True) + expense_groups = ExpenseGroup.objects.filter(expenses__id__in=[expense_ids], workspace_id=workspace.id).distinct('id').values('id') + expense_group_ids = [expense_group['id'] for expense_group in expense_groups] + + export_to_qbo(workspace.id, None, expense_group_ids) except Exception: handle_import_exception(task_log) diff --git a/apps/workspaces/actions.py b/apps/workspaces/actions.py index a3d976dd..fe424ab9 100644 --- a/apps/workspaces/actions.py +++ b/apps/workspaces/actions.py @@ -232,16 +232,21 @@ def post_to_integration_settings(workspace_id: int, active: bool): logger.error(error) -def export_to_qbo(workspace_id, export_mode=None): +def export_to_qbo(workspace_id, export_mode=None, expense_group_ids=[]): general_settings = WorkspaceGeneralSettings.objects.get(workspace_id=workspace_id) last_export_detail = LastExportDetail.objects.get(workspace_id=workspace_id) last_exported_at = datetime.now() is_expenses_exported = False export_mode = export_mode or 'MANUAL' + expense_group_filters = { + 'exported_at__isnull': True, + 'workspace_id': workspace_id + } + if expense_group_ids: + expense_group_filters['id__in'] = expense_group_ids if general_settings.reimbursable_expenses_object: - - expense_group_ids = ExpenseGroup.objects.filter(fund_source='PERSONAL', exported_at__isnull=True, workspace_id=workspace_id).values_list('id', flat=True) + expense_group_ids = ExpenseGroup.objects.filter(fund_source='PERSONAL', **expense_group_filters).values_list('id', flat=True) if len(expense_group_ids): is_expenses_exported = True @@ -279,7 +284,7 @@ def export_to_qbo(workspace_id, export_mode=None): ) if general_settings.corporate_credit_card_expenses_object: - expense_group_ids = ExpenseGroup.objects.filter(fund_source='CCC', exported_at__isnull=True, workspace_id=workspace_id).values_list('id', flat=True) + expense_group_ids = ExpenseGroup.objects.filter(fund_source='CCC', **expense_group_filters).values_list('id', flat=True) if len(expense_group_ids): is_expenses_exported = True