From c8e8a1c05bcc074f5b54a59be0e28e413d729d83 Mon Sep 17 00:00:00 2001 From: anishfyle Date: Mon, 16 Dec 2024 16:21:26 +0530 Subject: [PATCH] fix --- apps/quickbooks_online/utils.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/quickbooks_online/utils.py b/apps/quickbooks_online/utils.py index 2c60fe6e..ff111a7c 100644 --- a/apps/quickbooks_online/utils.py +++ b/apps/quickbooks_online/utils.py @@ -712,7 +712,6 @@ def get_override_tax_details(self, lines, is_journal_entry_export: bool = False) def purchase_object_payload(self, purchase_object, line, payment_type, account_ref, doc_number: str = None, credit=None): general_settings = WorkspaceGeneralSettings.objects.filter(workspace_id=self.workspace_id).first() - qbo_credentials = QBOCredential.objects.get(workspace_id=self.workspace_id) purchase_object_payload = { 'DocNumber': doc_number if doc_number else None, @@ -727,22 +726,10 @@ def purchase_object_payload(self, purchase_object, line, payment_type, account_r 'Line': line, } - # Add exchange rate for foreign currency transactions - if general_settings.is_multi_currency_allowed and purchase_object.currency != qbo_credentials.currency and qbo_credentials.currency: - exchange_rate = self.connection.exchange_rates.get_by_source(source_currency_code=purchase_object.currency) - purchase_object_payload['ExchangeRate'] = exchange_rate['Rate'] if "Rate" in exchange_rate else 1 - - if isinstance(purchase_object, CreditCardPurchase): - purchase_object.exchange_rate = purchase_object_payload['ExchangeRate'] - purchase_object.save(update_fields=['exchange_rate']) - if general_settings.import_tax_codes: if general_settings.is_tax_override_enabled: tax_details = self.get_override_tax_details(line) - purchase_object_payload.update({ - 'GlobalTaxCalculation': 'TaxExcluded', - 'TxnTaxDetail': {"TaxLine": tax_details} - }) + purchase_object_payload.update({'GlobalTaxCalculation': 'TaxExcluded', 'TxnTaxDetail': {"TaxLine": tax_details}}) else: purchase_object_payload.update({'GlobalTaxCalculation': 'TaxInclusive'}) @@ -1062,6 +1049,7 @@ def __construct_credit_card_purchase(self, credit_card_purchase: CreditCardPurch :return: constructed credit_card_purchase """ general_mappings = GeneralMapping.objects.filter(workspace_id=self.workspace_id).first() + general_settings = WorkspaceGeneralSettings.objects.filter(workspace_id=self.workspace_id).first() qbo_home_currency = QBOCredential.objects.get(workspace_id=self.workspace_id).currency fyle_home_currency = credit_card_purchase.currency @@ -1077,6 +1065,13 @@ def __construct_credit_card_purchase(self, credit_card_purchase: CreditCardPurch credit_card_purchase_payload = self.purchase_object_payload(credit_card_purchase, line, account_ref=credit_card_purchase.ccc_account_id, payment_type='CreditCard', doc_number=credit_card_purchase.credit_card_purchase_number, credit=credit) + if general_settings.is_multi_currency_allowed and fyle_home_currency != qbo_home_currency and qbo_home_currency: + exchange_rate = self.connection.exchange_rates.get_by_source(source_currency_code=fyle_home_currency) + credit_card_purchase_payload['ExchangeRate'] = exchange_rate['Rate'] if "Rate" in exchange_rate else 1 + + credit_card_purchase.exchange_rate = credit_card_purchase_payload['ExchangeRate'] + credit_card_purchase.save(update_fields=['exchange_rate']) + logger.info("| Payload for Credit Card Purchase creation | Content: {{WORKSPACE_ID: {} EXPENSE_GROUP_ID: {} CREDIT_CARD_PURCHASE_PAYLOAD: {}}}".format(self.workspace_id, credit_card_purchase.expense_group.id, credit_card_purchase_payload)) return credit_card_purchase_payload