diff --git a/apps/xero/tasks.py b/apps/xero/tasks.py index 4832b11b..d37cd630 100644 --- a/apps/xero/tasks.py +++ b/apps/xero/tasks.py @@ -5,9 +5,8 @@ from typing import List from dateutil.relativedelta import relativedelta -from django.utils import timezone as django_timezone - from django.db import transaction +from django.utils import timezone as django_timezone from fyle_accounting_mappings.models import DestinationAttribute, ExpenseAttribute, Mapping from fyle_integrations_platform_connector import PlatformConnector from xerosdk.exceptions import UnsuccessfulAuthentication, WrongParamsError @@ -300,7 +299,7 @@ def create_bill( expense_group.response_logs = created_bill expense_group.save() resolve_errors_for_exported_expense_group(expense_group) - generate_export_url_and_update_expense(expense_group, 'BILL') + logger.info('Updated Expense Group %s successfully', expense_group.id) # Assign billable expenses to customers @@ -320,12 +319,17 @@ def create_bill( attach_customer_to_export(xero_connection, task_log) - load_attachments( - xero_connection, - created_bill["Invoices"][0]["InvoiceID"], - "invoices", - expense_group, - ) + try: + generate_export_url_and_update_expense(expense_group, 'BILL') + except Exception as e: + logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e) + + load_attachments( + xero_connection, + created_bill["Invoices"][0]["InvoiceID"], + "invoices", + expense_group, + ) def get_linked_transaction_object(export_instance, line_items: list): @@ -473,7 +477,7 @@ def create_bank_transaction( expense_group.response_logs = created_bank_transaction expense_group.save() resolve_errors_for_exported_expense_group(expense_group) - generate_export_url_and_update_expense(expense_group, 'BANK TRANSACTION') + logger.info('Updated Expense Group %s successfully', expense_group.id) # Assign billable expenses to customers @@ -497,12 +501,17 @@ def create_bank_transaction( attach_customer_to_export(xero_connection, task_log) - load_attachments( - xero_connection, - created_bank_transaction["BankTransactions"][0]["BankTransactionID"], - "banktransactions", - expense_group, - ) + try: + generate_export_url_and_update_expense(expense_group, 'BANK TRANSACTION') + except Exception as e: + logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e) + + load_attachments( + xero_connection, + created_bank_transaction["BankTransactions"][0]["BankTransactionID"], + "banktransactions", + expense_group, + ) def __validate_expense_group(expense_group: ExpenseGroup):