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

Feature: Multicurrency support (plus some bug fixes for double entry models) #134

Merged
merged 19 commits into from
Jul 22, 2024

Conversation

fivetran-avinash
Copy link
Contributor

@fivetran-avinash fivetran-avinash commented Jul 8, 2024

PR Overview

This PR will address the following Issue/Feature: [#128] (duplicate issue: #115), as well as bugfix [#135]. (Issue #127 was also validated/merged into this PR branch as well)

This PR will result in the following new package version:

v0.14.0

The introduction of new fields to support multicurrency makes this a breaking change.

Please provide the finalized CHANGELOG entry which details the relevant changes included in this PR:

🚨 Breaking Changes 🚨

Feature Requests: Multicurrency Support

  • We have introduced multicurrency support to the following models by providing these new fields that convert transaction amounts by their exchange rates. (PR #134)
  • We have kept the existing cash value fields that provides amounts and balances to ensure full coverage to customers regardless of their currency setup. (PR #134)
  • The new multicurrency fields that fulfill the same function as the respective existing fields is below:
Model New Multicurrency Fields Respective Single Currency Fields
quickbooks__general_ledger adjusted_converted_amount, running_converted_balance adjusted_amount, running_balance
quickbooks__general_ledger_by_period period_net_converted_change, period_beginning_converted_balance, period_ending_converted_balance period_net_change, period_beginning_balance, period_ending_balance
quickbooks__profit_and_loss converted_amount amount
quickbooks__balance_sheet converted_amount amount
quickbooks__cash_flow_statement cash_converted_ending_period, cash_converted_beginning_period, cash_converted_net_period cash_ending_period, cash_beginning_period, cash_net_period
quickbooks__ap_ar_enhanced total_converted_amount, estimate_total_converted_amount, total_current_converted_payment total_amount, estimate_total_amount, total_current_payment
quickbooks__expenses_sales_enhanced total_converted_amount, converted_amount total_amount, amount
  • Introduced *_converted_* type fields in our intermediate models to convert amounts where exchange rates exist for those transactions. If there is no exchange rate, these *_converted_* fields will default back to the already existing fields created for single currency, and all downstream calculations should match the single currency amount, balance and cash values. (PR #134)
  • For double-entry models that applied a cross-join to either AP/AR accounts, we added joins based on the currency_id value in the accounts source table for those transactions. (PR #134)
  • In the analysis folder, added the converted_balance to the quickbooks__balance_sheet and ending_converted_balance to the quickbooks__income_statement models. (PR #134)

Bug Fixes

  • Adjusted logic for discount sales receipt lines in int_quickbooks__sales_receipt_double_entry model to bring in these values properly as negative adjusted amounts in the quickbooks__general_ledger.
    (PR #130)
  • Applied filter in int_quickbooks__invoice_double_entry to filter out 'Accounts Receivable' accounts that are inactive. (PR #134)

Under the Hood

  • Added consistency and integrity tests within integration tests for the quickbooks__general_ledger, quickbooks__general_ledger_by_period, quickbooks__balance_sheet, quickbooks__cash_flow_statement and quickbooks__profit_and_loss models. (PR #130) & (PR 134)

Documentation Update

PR Checklist

Basic Validation

Please acknowledge that you have successfully performed the following commands locally:

  • dbt run –full-refresh && dbt test
  • [NA] dbt run (if incremental models are present) && dbt test

Before marking this PR as "ready for review" the following have been applied:

  • The appropriate issue has been linked, tagged, and properly assigned
  • All necessary documentation and version upgrades have been applied
  • docs were regenerated (unless this PR does not include any code or yml updates)
  • BuildKite integration tests are passing
  • Detailed validation steps have been provided below

Detailed Validation

Please share any and all of your validation steps:

A host of new validation tests have been added to our most used end models, as mentioned above. These will check for consistency of amounts between dev and prod (we only look at the regular amount for now, as converted_amount doesn't exist in prod at this moment--we will probably need to update this in a future round of validation testing), and then integrity tests assessing no changes on amounts and converted amounts for the various end model grains.

Screenshot 2024-07-17 at 3 14 46 AM

There were also regular consistency tests looking at row values for ap_ar_enhanced and expense_sales_enhanced. These tests will be modified before deploying to main.

One thing to call out is you will have to configure the vars in the integration_tests/dbt_project.yml to get the enabled_union_models macro to work properly in the general_ledger_amounts_match test model.

vars:
using_bill: true
using_credit_card_payment_txn: true

If you had to summarize this PR in an emoji, which would it be?

💴 💷 💶

@fivetran-avinash fivetran-avinash changed the base branch from main to release/v0.14.0 July 8, 2024 10:52
@fivetran-avinash fivetran-avinash changed the title Feature/multicurrency support Feature: Multicurrency support (plus some bug fixes for double entry models) Jul 17, 2024
@fivetran-avinash fivetran-avinash marked this pull request as ready for review July 17, 2024 16:31
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.

@fivetran-avinash fantastic work on this PR! I have a few questions, comments, and suggestions below. Let me know if you want to sync on any of my comments. Thanks!

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
models/intermediate/int_quickbooks__bill_join.sql Outdated Show resolved Hide resolved
cast(null as {{ dbt.type_string() }}) as estimate_status,

{% endif %}

invoice_link.due_date as due_date,
(payments.total_amount * coalesce(payments.exchange_rate, 1)) as total_current_converted_payment,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to a previous question, is there a related field to this which is available in prod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment on int_quickbooks__invoice_join for the update

models/quickbooks__general_ledger.sql Outdated Show resolved Hide resolved
models/quickbooks.yml Outdated Show resolved Hide resolved
models/quickbooks.yml Outdated Show resolved Hide resolved
packages.yml Outdated
Comment on lines 2 to 7
# version: [">=0.10.0", "<0.11.0"]

- git: https://github.com/fivetran/dbt_quickbooks_source.git
revision: feature/add-home-total-amount-to-deposit
warn-unpinned: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder to swap before merging

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 Addressed all PR notes/reran tests/regenerated docs. Should be ready for re-review.

dev as (
select *
--remove the below line before merging to main
except(converted_amount, total_converted_amount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fivetran-avinash Reminder to remove except clause before merging.

dev as (
select *
--remove the below line before merging to main
except (total_converted_amount, estimate_total_converted_amount, total_current_converted_payment)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fivetran-avinash Reminder to remove except clause before merging.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
models/quickbooks.yml Outdated Show resolved Hide resolved
models/quickbooks.yml Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
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.

@fivetran-avinash great work on this PR and thanks for addressing the outstanding items. I have a few very minor comments. Otherwise this PR is good to go!

README.md Outdated

> Please be aware that the [dbt_quickbooks](https://github.com/fivetran/dbt_quickbooks) and [dbt_quickbooks_source](https://github.com/fivetran/dbt_quickbooks_source) packages were developed with single currency company data. As such, the package models will not reflect accurate totals if your QuickBooks account has Multi-Currency enabled.
> [dbt_quickbooks](https://github.com/fivetran/dbt_quickbooks) and [dbt_quickbooks_source](https://github.com/fivetran/dbt_quickbooks_source) now supports multicurrency by bringing in values by specifying `*_converted_*` values for cash. More details are [available in the DECISIONLOG](https://github.com/fivetran/dbt_quickbooks/blob/main/DECISIONLOG.md#multicurrency-vs-single-currency-configuration).
Copy link
Contributor

Choose a reason for hiding this comment

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

Small wording suggestion update.

Suggested change
> [dbt_quickbooks](https://github.com/fivetran/dbt_quickbooks) and [dbt_quickbooks_source](https://github.com/fivetran/dbt_quickbooks_source) now supports multicurrency by bringing in values by specifying `*_converted_*` values for cash. More details are [available in the DECISIONLOG](https://github.com/fivetran/dbt_quickbooks/blob/main/DECISIONLOG.md#multicurrency-vs-single-currency-configuration).
> [dbt_quickbooks](https://github.com/fivetran/dbt_quickbooks) and [dbt_quickbooks_source](https://github.com/fivetran/dbt_quickbooks_source) now supports multicurrency by bringing in values by specifying `*_converted_*` values for cash amounts. More details are [available in the DECISIONLOG](https://github.com/fivetran/dbt_quickbooks/blob/main/DECISIONLOG.md#multicurrency-vs-single-currency-configuration).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

README.md Outdated
> Please be aware that the [dbt_quickbooks](https://github.com/fivetran/dbt_quickbooks) and [dbt_quickbooks_source](https://github.com/fivetran/dbt_quickbooks_source) packages were developed with single currency company data. As such, the package models will not reflect accurate totals if your QuickBooks account has Multi-Currency enabled.
> [dbt_quickbooks](https://github.com/fivetran/dbt_quickbooks) and [dbt_quickbooks_source](https://github.com/fivetran/dbt_quickbooks_source) now supports multicurrency by bringing in values by specifying `*_converted_*` values for cash. More details are [available in the DECISIONLOG](https://github.com/fivetran/dbt_quickbooks/blob/main/DECISIONLOG.md#multicurrency-vs-single-currency-configuration).

There are specific limitations if you need converted amounts for credit card payments and transfers, as we do not currently have the ability to validate a best approach to convert the original amounts into their proper home currency. [Please open an issue with us](https://github.com/fivetran/dbt_quickbooks/issues/new/choose) if this is critical and/or you believe you can help contribute to scoping out adding that functionality in..
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like this section! One small edit.

Suggested change
There are specific limitations if you need converted amounts for credit card payments and transfers, as we do not currently have the ability to validate a best approach to convert the original amounts into their proper home currency. [Please open an issue with us](https://github.com/fivetran/dbt_quickbooks/issues/new/choose) if this is critical and/or you believe you can help contribute to scoping out adding that functionality in..
There are specific limitations if you need converted amounts for credit card payments and transfers, as we do not currently have the ability to validate a best approach to convert the original amounts into their proper home currency. [Please open an issue with us](https://github.com/fivetran/dbt_quickbooks/issues/new/choose) if this is critical and/or you believe you can help contribute to scoping out adding that functionality in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

models/intermediate/int_quickbooks__bill_join.sql Outdated Show resolved Hide resolved
Copy link
Contributor

@fivetran-catfritz fivetran-catfritz left a comment

Choose a reason for hiding this comment

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

@fivetran-avinash This is generally looking great--I just have one small question!

# For validation testing.
# This below vars configuration is needed for the `general_ledger_amounts_match` macro.
using_bill: true
using_credit_card_payment_txn: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the default for using_credit_card_payment_txn is false but we're setting it true here, should we set it to false in this line so one run tests true and the other false? Or, you could just comment out this L70 when sending to buildkite?

Also I'm not sure if it would be related to this PR, it looks like the default value is set as false everywhere except for here. Is that intentional?

Copy link
Contributor Author

@fivetran-avinash fivetran-avinash Jul 19, 2024

Choose a reason for hiding this comment

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

@fivetran-catfritz Oh good catch. This should have been commented out, will fix now.

In the second link, I believe this is false by default? It's conditional on the variable being true.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fivetran-avinash According to the docs, {% var('using_credit_card_payment_txn', True) %} means the default value is True.
The line {% if var('using_credit_card_payment_txn', True) %} simply evaluates if the variable value provided is true/false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fivetran-catfritz Ahh, good catch! Yes it should probably be consistent then.

Interestingly, I don't think the behavior changes very much unless the variable is not set, but since it is set by default the cases that it wouldn't be set are probably rare, which is why this hasn't been flagged.

Copy link
Contributor

@fivetran-catfritz fivetran-catfritz left a comment

Choose a reason for hiding this comment

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

Awesome! LGTM.

@fivetran-avinash fivetran-avinash merged commit e76e353 into release/v0.14.0 Jul 22, 2024
8 checks passed
@fivetran-avinash fivetran-avinash mentioned this pull request Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants