From c64bec48b66f0c0324bbd9c096cb16767a6e595a Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:15:46 +0530 Subject: [PATCH] In progress bug (#264) * in progress bug fix * issue resolved --------- Co-authored-by: Ashutosh619-sudo --- apps/xero/exceptions.py | 3 +++ apps/xero/tasks.py | 37 +++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/apps/xero/exceptions.py b/apps/xero/exceptions.py index 5ed8a9c8..5414274d 100644 --- a/apps/xero/exceptions.py +++ b/apps/xero/exceptions.py @@ -137,10 +137,13 @@ def new_fn(*args): expense_group_id = args[0] expense_group = ExpenseGroup.objects.get(id=expense_group_id) task_log_id = args[1] + xero_connection = args[2] task_log = TaskLog.objects.get(id=task_log_id) workspace_id = expense_group.workspace_id try: + if not payment and not xero_connection: + raise XeroCredentials.DoesNotExist func(*args) except (FyleCredential.DoesNotExist, InvalidTokenError): diff --git a/apps/xero/tasks.py b/apps/xero/tasks.py index 1855ec48..c3f27448 100644 --- a/apps/xero/tasks.py +++ b/apps/xero/tasks.py @@ -266,29 +266,26 @@ def create_chain_and_export(chaining_attributes: list, workspace_id: int) -> Non try: xero_credentials = XeroCredentials.get_active_xero_credentials(workspace_id) xero_connection = XeroConnector(xero_credentials, workspace_id) + except (UnsuccessfulAuthentication, XeroCredentials.DoesNotExist): + xero_connection = None - chain = Chain() + chain = Chain() - fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id) - chain.append("apps.fyle.tasks.sync_dimensions", fyle_credentials) - - for group in chaining_attributes: - trigger_function = "apps.xero.tasks.create_{}".format(group["export_type"]) - chain.append( - trigger_function, - group["expense_group_id"], - group["task_log_id"], - xero_connection, - group["last_export"], - ) - - if chain.length() > 1: - chain.run() + fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id) + chain.append("apps.fyle.tasks.sync_dimensions", fyle_credentials) + + for group in chaining_attributes: + trigger_function = "apps.xero.tasks.create_{}".format(group["export_type"]) + chain.append( + trigger_function, + group["expense_group_id"], + group["task_log_id"], + xero_connection, + group["last_export"], + ) - except UnsuccessfulAuthentication: - logger.info("Xero refresh token is invalid for workspace_id - %s", workspace_id) - except XeroCredentials.DoesNotExist: - logger.info("Xero Credentials not found for workspace_id %s", workspace_id) + if chain.length() > 1: + chain.run() def schedule_bills_creation(workspace_id: int, expense_group_ids: List[str]) -> list: