Skip to content

Commit

Permalink
Merge pull request #73 from fivetran/feature/disable-exchange-rate-va…
Browse files Browse the repository at this point in the history
…riable

[Feature] Add exchange rate variable
  • Loading branch information
fivetran-avinash authored Jul 26, 2023
2 parents 9761bf4 + 287fd08 commit 8d6a122
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ dbt deps
dbt seed --target "$db" --full-refresh
dbt run --target "$db" --full-refresh
dbt test --target "$db"
dbt run --vars '{netsuite2__multibook_accounting_enabled: false, netsuite2__using_vendor_categories: false}' --target "$db" --full-refresh
dbt run --vars '{netsuite2__multibook_accounting_enabled: false, netsuite2__using_exchange_rate: false, netsuite2__using_vendor_categories: false, netsuite2__using_jobs: false}' --target "$db" --full-refresh
dbt test --target "$db"
dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target/
dbt_modules/
logs/
.DS_Store
dbt_packages/
dbt_packages/
env/
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# dbt_netsuite v0.UPDATE.UPDATE
# dbt_netsuite v0.8.1
[PR #73](https://github.com/fivetran/dbt_netsuite/pull/73) applies the following changes:

## Under the Hood:
## 🎉 Feature Updates 🎉
- Introduces variable `netsuite2__using_exchange_rate` to allow users who don't utilize exchange rates in Netsuite2 the ability to disable that functionality, and return only the unconverted amount as the final converted amount.
- This variable will also disable upstream models utilizing exchange rates, since they only flow into the intermediate model that converts amounts into their default subsidiary currency.
- **IMPORTANT**: The `netsuite2__using_exchange_rate` variable has also been implemented in the [`dbt_netsuite_source` package](https://github.com/fivetran/dbt_netsuite), so be sure to set it globally by inserting this code into your `dbt_project.yml`:
```yml
vars:
netsuite2__using_exchange_rate: false
```
- Updated documentation in `netsuite2.yml` to provide context on how disabling exchange rates impacts specific models.

## 🔧 Under the Hood 🔩
- Incorporated the new `fivetran_utils.drop_schemas_automation` macro into the end of each Buildkite integration test job.
- Updated the pull request [templates](/.github).

# dbt_netsuite v0.8.0
[PR #66](https://github.com/fivetran/dbt_netsuite/pull/66) applies the following changes:

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ It's possible that your Netsuite connector does not sync every table that this p
```yml
vars:
netsuite2__multibook_accounting_enabled: false # True by default. Disable `accountingbooksubsidiary` and `accountingbook` if you are not using the Multi-Book Accounting feature
netsuite2__using_exchange_rate: false #True by default. Disable `exchange_rate` if you don't utilize exchange rates. If you set this variable to false, ensure it is scoped globally so that the `netsuite_source` package can access it as well.
netsuite2__using_vendor_categories: false # True by default. Disable `vendorcategory` if you don't categorize your vendors
netsuite2__using_jobs: false # True by default. Disable `job` if you don't use jobs
```
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 2
name: 'netsuite'
version: '0.8.0'
version: '0.8.1'
require-dbt-version: [">=1.3.0", "<2.0.0"]

models:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/run_results.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions integration_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
dbt_modules/
dbt_packages/
env/
logs/
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'netsuite_integration_tests'
version: '0.8.0'
version: '0.8.1'
profile: 'integration_tests'
config-version: 2
models:
Expand Down
28 changes: 16 additions & 12 deletions models/netsuite2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ models:
- name: int_netsuite2__acctxperiod_exchange_rate_map
description: >
(Step 1/4) In order to accurately recreate the balance sheet and income statement,
it is necessary to convert all transaction amounts into the currency of
the parent subsidiary. The logic gets complicated fast, mostly because
of the behavior of the balance sheet. On the balance sheet, the conversion
rate you use for a single transaction will differ by accounting period.
it is necessary to convert all transaction amounts into the parent subsidiary currency.
The logic gets complicated because of balance sheet behavior. On the balance sheet,
the conversion rate you use for a single transaction will differ by accounting period.
For example, if a transaction took place in August, and you are generating
balances for the December period, you will need to convert the August transaction
using the December conversion rate.
using December's conversion rate.
The first step here is to create a mapping of all accounting periods and the
respective exchange rates, by subsidiary. This is called period_exchange_rate_map
So we created a mapping of all accounting periods and the respective
exchange rates, by subsidiary, naming it period_exchange_rate_map.
Next, we cross join the accounts table to the period_exchange_rate_map, so we can
generate a map of exchange rates, by account, accounting period, and subsidiary.
Next, we cross join the accounts table to the period_exchange_rate_map,
generating a map of exchange rates, by account, accounting period, and subsidiary.
NOTE: This is only applicable if you're using exchange rates. Consult the README on how to
disable exchange rates using the `netsuite2__using_exchange_rate` in your dbt_project.yml.
- name: int_netsuite2__tran_lines_w_accounting_period
description: >
Expand All @@ -36,9 +38,11 @@ models:
- name: int_netsuite2__tran_with_converted_amounts
description: >
(Step 4/4) Now that we have the exchange rates and the unconverted amounts, the next step is
to calculate the converted total.
Additionally, we add in a couple of extra fields that will help us in our final balance sheet
and income statement queries.
to calculate the converted total. Additionally, we add in a couple of extra fields that will
help us in our final balance sheet and income statement queries.
Note: This is only applicable if you're using exchange rates. See the README for instructions
on how to disable exchange rates using the `netsuite2__using_exchange_rate` in your dbt_project.yml.
- name: netsuite2__balance_sheet
description: >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ config(enabled=(var('netsuite_data_model', 'netsuite') == var('netsuite_data_model_override','netsuite2') and var('netsuite2__multibook_accounting_enabled', true))) }}
{{ config(enabled=(var('netsuite_data_model', 'netsuite') == var('netsuite_data_model_override','netsuite2') and var('netsuite2__multibook_accounting_enabled', true) and var('netsuite2__using_exchange_rate', true))) }}

with consolidated_exchange_rates as (

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ config(enabled=var('netsuite_data_model', 'netsuite') == var('netsuite_data_model_override','netsuite2')) }}
{{ config(enabled=var('netsuite_data_model', 'netsuite') == var('netsuite_data_model_override','netsuite2') and var('netsuite2__using_exchange_rate', true)) }}

with accounts as (
select *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ with transaction_lines_w_accounting_period as (
from {{ ref('int_netsuite2__tran_lines_w_accounting_period') }}
),

accountxperiod_exchange_rate_map as (
select *
from {{ ref('int_netsuite2__acctxperiod_exchange_rate_map') }}
),
{% if var('netsuite2__using_exchange_rate', true) %}
accountxperiod_exchange_rate_map as (
select *
from {{ ref('int_netsuite2__acctxperiod_exchange_rate_map') }}
),
{% endif %}

transaction_and_reporting_periods as (
select *
Expand All @@ -23,14 +25,19 @@ accounts as (
transactions_in_every_calculation_period_w_exchange_rates as (
select
transaction_lines_w_accounting_period.*,
reporting_accounting_period_id,
exchange_reporting_period.exchange_rate as exchange_rate_reporting_period,
exchange_transaction_period.exchange_rate as exchange_rate_transaction_period
reporting_accounting_period_id

{% if var('netsuite2__using_exchange_rate', true) %}
, exchange_reporting_period.exchange_rate as exchange_rate_reporting_period
, exchange_transaction_period.exchange_rate as exchange_rate_transaction_period
{% endif %}

from transaction_lines_w_accounting_period

left join transaction_and_reporting_periods
on transaction_and_reporting_periods.accounting_period_id = transaction_lines_w_accounting_period.transaction_accounting_period_id

{% if var('netsuite2__using_exchange_rate', true) %}
left join accountxperiod_exchange_rate_map as exchange_reporting_period
on exchange_reporting_period.accounting_period_id = transaction_and_reporting_periods.reporting_accounting_period_id
and exchange_reporting_period.account_id = transaction_lines_w_accounting_period.account_id
Expand All @@ -40,13 +47,19 @@ transactions_in_every_calculation_period_w_exchange_rates as (
on exchange_transaction_period.accounting_period_id = transaction_and_reporting_periods.accounting_period_id
and exchange_transaction_period.account_id = transaction_lines_w_accounting_period.account_id
and exchange_transaction_period.from_subsidiary_id = transaction_lines_w_accounting_period.subsidiary_id
{% endif %}
),

transactions_with_converted_amounts as (
select
transactions_in_every_calculation_period_w_exchange_rates.*,
{% if var('netsuite2__using_exchange_rate', true) %}
unconverted_amount * exchange_rate_transaction_period as converted_amount_using_transaction_accounting_period,
unconverted_amount * exchange_rate_reporting_period as converted_amount_using_reporting_month,
{% else %}
unconverted_amount as converted_amount_using_transaction_accounting_period,
unconverted_amount as converted_amount_using_reporting_month,
{% endif %}
case
when lower(accounts.type_name) in ('income','other income','expense','other expense','other income','cost of goods sold') then true
else false
Expand Down

0 comments on commit 8d6a122

Please sign in to comment.