Skip to content

[Prerelease] Apply home currency exchange rate to fix unneeded multicurrency issues. #188

Open
fivetran-avinash wants to merge 9 commits intomainfrom
prerelease/home-currency-exchange-rate-logic
Open

[Prerelease] Apply home currency exchange rate to fix unneeded multicurrency issues. #188
fivetran-avinash wants to merge 9 commits intomainfrom
prerelease/home-currency-exchange-rate-logic

Conversation

@fivetran-avinash
Copy link
Contributor

@fivetran-avinash fivetran-avinash commented Nov 20, 2025

PR Overview

Package version introduced in this PR:

  • 1.1.1-a2

This PR addresses the following Issue/Feature(s):

  • Pre-release to allow more multicurrency flexibilty for a home currency exchange rate variable.

Summary of changes:

  • Ensures that amounts that aren't already in a home currency aren't converted. Pins "USD" to satisfy a specific customer.

Submission Checklist

  • Alignment meeting with the reviewer (if needed)
    • Timeline and validation requirements discussed
  • Provide validation details:
    • Validation Steps: Check for unintentional effects (e.g., add/run consistency & integrity tests)
    • Testing Instructions: Confirm the change addresses the issue(s)
    • Focus Areas: Complex logic or queries that need extra attention
  • Merge any relevant open PRs into this PR

Changelog

  • Draft changelog for PR
  • Final changelog for release review

@fivetran-avinash fivetran-avinash self-assigned this Nov 20, 2025
@fivetran-avinash fivetran-avinash changed the title [Prerelease] Apply home currency exchange rate. [Prerelease] Apply home currency exchange rate to fix unneeded multicurrency issues. Nov 20, 2025
Copy link
Contributor

@fivetran-joemarkiewicz fivetran-joemarkiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments before pre-release approval

Comment on lines 215 to 223
case
when invoices.currency_id = '{{ var('quickbooks__home_currency', '') }}'
then case when invoice_lines.bundle_id is not null and invoices.total_amount = 0
then invoices.total_amount
else coalesce(invoice_bundles.amount, invoice_lines.amount)
end
when invoice_lines.bundle_id is not null and invoices.total_amount = 0
then invoices.total_amount * coalesce(invoices.exchange_rate, 1)
else coalesce(invoice_bundles.amount, invoice_lines.amount) * coalesce(invoices.exchange_rate, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an effort to not maintain two versions of the same original case statement I believe we should only use the variable case when on the original lines 215 and 216 where it's required. Otherwise, I worry about us updating one of these case statements and not updating the other in a future update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, I'm thinking something along the lines of the following (this will need to be verified):

Suggested change
case
when invoices.currency_id = '{{ var('quickbooks__home_currency', '') }}'
then case when invoice_lines.bundle_id is not null and invoices.total_amount = 0
then invoices.total_amount
else coalesce(invoice_bundles.amount, invoice_lines.amount)
end
when invoice_lines.bundle_id is not null and invoices.total_amount = 0
then invoices.total_amount * coalesce(invoices.exchange_rate, 1)
else coalesce(invoice_bundles.amount, invoice_lines.amount) * coalesce(invoices.exchange_rate, 1)
case when invoice_lines.bundle_id is not null and invoices.total_amount = 0
then
case when invoices.currency_id = '{{ var('quickbooks__home_currency', '') }}'
then invoices.total_amount
else (invoices.total_amount * coalesce(invoices.exchange_rate, 1))
else
case when invoices.currency_id = '{{ var('quickbooks__home_currency', '') }}'
then coalesce(invoice_bundles.amount, invoice_lines.amount)
else (coalesce(invoice_bundles.amount, invoice_lines.amount) * coalesce(invoices.exchange_rate, 1))

This way the original case statement persists with no repeated logic other than the variable case statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was realizing this code is a bit repetitive, so I tried and simplified it to separate out the bundle component of this logic and the exchange rate application. Whiteboarded it and I believe it retains the initial logic. Let me know your thoughts.

Comment on lines 146 to 153
case when sales_receipts.currency_id = '{{ var('quickbooks__home_currency', '') }}'
then case when sales_receipt_lines.discount_account_id is not null
then sales_receipt_lines.amount * (-1)
else sales_receipt_lines.amount
end
when sales_receipt_lines.discount_account_id is not null
then sales_receipt_lines.amount * coalesce(-sales_receipts.exchange_rate, -1)
else sales_receipt_lines.amount * coalesce(sales_receipts.exchange_rate, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as the other multi case statement and leaning more towards only maintaining one version of the original case statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also simplified the logic here, let me know your thoughts.

Copy link
Contributor Author

@fivetran-avinash fivetran-avinash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fivetran-joemarkiewicz Ready for re-review.

@fivetran-avinash fivetran-avinash added docs:ready Triggers the docs generator workflow. pre-release Triggers the auto-releaser workflow. labels Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs:ready Triggers the docs generator workflow. pre-release Triggers the auto-releaser workflow.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants