Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anishfyle committed Dec 16, 2024
1 parent 5ee22e0 commit c8e8a1c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions apps/quickbooks_online/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'})

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit c8e8a1c

Please sign in to comment.