diff --git a/apps/xero/tasks.py b/apps/xero/tasks.py index 1deca1b4..4e815336 100644 --- a/apps/xero/tasks.py +++ b/apps/xero/tasks.py @@ -5,31 +5,22 @@ from typing import List from django.db import transaction - from fyle_accounting_mappings.models import DestinationAttribute, ExpenseAttribute, Mapping - from fyle_integrations_platform_connector import PlatformConnector - -from fyle_xero_api.exceptions import BulkError - from xerosdk.exceptions import UnsuccessfulAuthentication, WrongParamsError -from apps.fyle.models import Expense, ExpenseGroup, Reimbursement +from apps.fyle.actions import update_complete_expenses, update_expenses_in_progress from apps.fyle.enums import FundSourceEnum, FyleAttributeEnum, PlatformExpensesEnum - +from apps.fyle.models import Expense, ExpenseGroup, Reimbursement +from apps.fyle.tasks import post_accounting_export_summary from apps.mappings.models import GeneralMapping, TenantMapping - +from apps.tasks.enums import ErrorTypeEnum, TaskLogStatusEnum, TaskLogTypeEnum from apps.tasks.models import Error, TaskLog -from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum, ErrorTypeEnum - from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings, XeroCredentials - from apps.xero.exceptions import handle_xero_exceptions from apps.xero.models import BankTransaction, BankTransactionLineItem, Bill, BillLineItem, Payment from apps.xero.utils import XeroConnector -from apps.fyle.actions import update_expenses_in_progress, update_complete_expenses -from apps.fyle.tasks import post_accounting_export_summary - +from fyle_xero_api.exceptions import BulkError logger = logging.getLogger(__name__) logger.level = logging.INFO @@ -841,14 +832,21 @@ def generate_export_url_and_update_expense(expense_group: ExpenseGroup, export_t :param expense_group: Expense Group :return: None """ + workspace = Workspace.objects.get(id=expense_group.workspace_id) try: if export_type == 'BILL': export_id = expense_group.response_logs['Invoices'][0]['InvoiceID'] - url = f'https://go.xero.com/AccountsPayable/View.aspx?invoiceID={export_id}' + if workspace.xero_short_code: + url = f'https://go.xero.com/organisationlogin/default.aspx?shortcode={workspace.xero_short_code}&redirecturl=/AccountsPayable/Edit.aspx?InvoiceID={export_id}' + else: + url = f'https://go.xero.com/AccountsPayable/View.aspx?invoiceID={export_id}' else: export_id = expense_group.response_logs['BankTransactions'][0]['BankTransactionID'] - account_id = expense_group.response_logs['BankTransactions'][0]['BankAccount.AccountID'] - url = f'https://go.xero.com/Bank/ViewTransaction.aspx?bankTransactionID={export_id}&accountID={account_id}' + account_id = expense_group.response_logs['BankTransactions'][0]['BankAccount']['AccountID'] + if workspace.xero_short_code: + url = f'https://go.xero.com/organisationlogin/default.aspx?shortcode={workspace.xero_short_code}&redirecturl=/Bank/ViewTransaction.aspx?bankTransactionID={export_id}' + else: + url = f'https://go.xero.com/Bank/ViewTransaction.aspx?bankTransactionID={export_id}&accountID={account_id}' except Exception as error: # Defaulting it to Intacct app url, worst case scenario if we're not able to parse it properly url = 'https://go.xero.com'