Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exchange rate for ccp #706

Closed
wants to merge 7 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 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,9 @@ 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

line = self.__construct_credit_card_purchase_lineitems(credit_card_purchase_lineitems, general_mappings)
credit = False
Expand All @@ -1075,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

anishfyle marked this conversation as resolved.
Show resolved Hide resolved
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
Loading