Skip to content

Commit

Permalink
Fix: Direct Export Complete sync (#571)
Browse files Browse the repository at this point in the history
* Fix: Direct Export Complete sync

* Fix Failed

* Fix Failed
  • Loading branch information
ruuushhh authored May 16, 2024
1 parent 6baf0f0 commit 0013cf2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion apps/fyle/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def group_expenses_and_save(expenses: List[Dict], task_log: TaskLog, workspace:
task_log.save()


def post_accounting_export_summary(org_id: str, workspace_id: int, fund_source: str = None) -> None:
def post_accounting_export_summary(org_id: str, workspace_id: int, fund_source: str = None, is_failed: bool = False) -> None:
"""
Post accounting export summary to Fyle
:param org_id: org id
Expand All @@ -219,6 +219,9 @@ def post_accounting_export_summary(org_id: str, workspace_id: int, fund_source:
if fund_source:
filters['fund_source'] = fund_source

if is_failed:
filters['accounting_export_summary__state'] = 'ERROR'

expenses_count = Expense.objects.filter(**filters).count()

accounting_export_summary_batches = []
Expand Down
1 change: 1 addition & 0 deletions apps/netsuite/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .actions import update_last_export_details
from apps.fyle.actions import update_failed_expenses
from apps.fyle.tasks import post_accounting_export_summary


from .errors import error_matcher, get_entity_values, replace_destination_id_with_values
Expand Down
2 changes: 1 addition & 1 deletion apps/netsuite/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __create_chain_and_run(fyle_credentials: FyleCredential, in_progress_expense
logger.info('Chain task %s, Chain Expense Group %s, Chain Task Log %s', task['target'], task['expense_group'], task['task_log_id'])
chain.append(task['target'], task['expense_group'], task['task_log_id'], task['last_export'])

chain.append('apps.fyle.tasks.post_accounting_export_summary', fyle_credentials.workspace.fyle_org_id, workspace_id, fund_source)
chain.append('apps.fyle.tasks.post_accounting_export_summary', fyle_credentials.workspace.fyle_org_id, workspace_id, fund_source, True)
chain.run()


Expand Down
7 changes: 6 additions & 1 deletion apps/netsuite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def resolve_errors_for_exported_expense_group(expense_group, workspace_id=None):


@handle_netsuite_exceptions(payment=False)
def create_bill(expense_group, task_log_id, last_export):
def create_bill(expense_group: ExpenseGroup, task_log_id, last_export):
task_log = TaskLog.objects.get(id=task_log_id)
logger.info('Creating Bill for Expense Group %s, current state is %s', expense_group.id, task_log.status)

Expand Down Expand Up @@ -483,6 +483,7 @@ def create_bill(expense_group, task_log_id, last_export):

resolve_errors_for_exported_expense_group(expense_group)
update_complete_expenses(expense_group.expenses.all(), expense_group.export_url)
post_accounting_export_summary(expense_group.workspace.fyle_org_id, expense_group.workspace.id, expense_group.fund_source)

logger.info('Updated Expense Group %s successfully', expense_group.id)
async_task(
Expand Down Expand Up @@ -561,6 +562,8 @@ def create_credit_card_charge(expense_group, task_log_id, last_export):
expense_group.export_url = generate_netsuite_export_url(response_logs=created_credit_card_charge, netsuite_credentials=netsuite_credentials)
expense_group.save()
update_complete_expenses(expense_group.expenses.all(), expense_group.export_url)
post_accounting_export_summary(expense_group.workspace.fyle_org_id, expense_group.workspace.id, expense_group.fund_source)

resolve_errors_for_exported_expense_group(expense_group)
logger.info('Updated Expense Group %s successfully', expense_group.id)

Expand Down Expand Up @@ -614,6 +617,7 @@ def create_expense_report(expense_group, task_log_id, last_export):
expense_group.save()
resolve_errors_for_exported_expense_group(expense_group)
update_complete_expenses(expense_group.expenses.all(), expense_group.export_url)
post_accounting_export_summary(expense_group.workspace.fyle_org_id, expense_group.workspace.id, expense_group.fund_source)

logger.info('Updated Expense Group %s successfully', expense_group.id)
async_task(
Expand Down Expand Up @@ -673,6 +677,7 @@ def create_journal_entry(expense_group, task_log_id, last_export):
expense_group.save()
resolve_errors_for_exported_expense_group(expense_group)
update_complete_expenses(expense_group.expenses.all(), expense_group.export_url)
post_accounting_export_summary(expense_group.workspace.fyle_org_id, expense_group.workspace.id, expense_group.fund_source)

logger.info('Updated Expense Group %s successfully', expense_group.id)
async_task(
Expand Down

0 comments on commit 0013cf2

Please sign in to comment.