Skip to content

Commit

Permalink
Fix export mode for Exports from Fyle | Export only selected reports (#…
Browse files Browse the repository at this point in the history
…516)

* Fix export mode for Exports from Fyle

* Export only selected reports
  • Loading branch information
ashwin1111 authored Nov 8, 2023
1 parent 6839a95 commit 30252d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion apps/fyle/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 9 additions & 4 deletions apps/workspaces/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30252d4

Please sign in to comment.