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

dbt_netsuite v0.13.0 release #117

Merged
merged 56 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e22707f
Added some of the transaction line booleans to allow downstream filte…
Mar 26, 2024
a53afc4
Add item id to be able to model it downstream as a kimball modell
Apr 5, 2024
d140a20
Add transaction_number for smoother downstream searching
Apr 5, 2024
a9a5f0d
Adding entity key to enable downstream processing
Apr 5, 2024
7a2639f
Merge pull request #2 from FrankTub/feature/transaction-details-fields
FrankTub Apr 5, 2024
63ab4c2
Add departments ID field
Apr 8, 2024
0eeb580
feature/performance-improvements
fivetran-catfritz Apr 10, 2024
d34f468
update materialization
fivetran-catfritz Apr 10, 2024
1766d88
upate macro
fivetran-catfritz Apr 10, 2024
dae8d3e
update macro
fivetran-catfritz Apr 10, 2024
e16de20
update macro
fivetran-catfritz Apr 10, 2024
bfee8ee
update macro
fivetran-catfritz Apr 10, 2024
1c125a7
update macro
fivetran-catfritz Apr 10, 2024
86919ed
update incremental strategy
fivetran-catfritz Apr 11, 2024
bc3e10a
update incremental strategy
fivetran-catfritz Apr 11, 2024
4e72657
updates
fivetran-catfritz Apr 11, 2024
73939cb
updates
fivetran-catfritz Apr 11, 2024
3f55827
update
fivetran-catfritz Apr 11, 2024
9e434b4
Fivetran documentation updates
fivetran-catfritz Apr 11, 2024
91066db
Update CHANGELOG.md
fivetran-catfritz Apr 11, 2024
5072f5f
add back partitions & update docs
fivetran-catfritz Apr 12, 2024
3e9969d
update readme
fivetran-catfritz Apr 12, 2024
3e4f4d2
update changelog
fivetran-catfritz Apr 12, 2024
83731ed
bigquery to tables
fivetran-catfritz Apr 13, 2024
e48243b
update docs
fivetran-catfritz Apr 15, 2024
3e46330
Merge branch 'release/v0.13.0-apr-2024' into feature/transaction-line…
fivetran-catfritz Apr 15, 2024
5decad7
Merge pull request #114 from FrankTub/feature/transaction-line-fields
fivetran-catfritz Apr 15, 2024
0b4200b
update docs
fivetran-catfritz Apr 15, 2024
f64f634
update changelog
fivetran-catfritz Apr 15, 2024
3ca4803
update spaces
fivetran-catfritz Apr 15, 2024
5224f13
update spaces
fivetran-catfritz Apr 15, 2024
5f42218
update lookback macro & set to_subsidiary default true
fivetran-catfritz Apr 17, 2024
8aaf181
update yml
fivetran-catfritz Apr 17, 2024
72e3af8
Apply suggestions from code review
fivetran-catfritz Apr 17, 2024
1bc585e
update run_models
fivetran-catfritz Apr 17, 2024
ab6112e
udpate run models
fivetran-catfritz Apr 17, 2024
3027320
update default for using to_subsidiary
fivetran-catfritz Apr 18, 2024
91e6d68
update macro
fivetran-catfritz Apr 18, 2024
1ae71c5
Documentation update
fivetran-avinash Apr 19, 2024
26469f1
Merge pull request #118 from fivetran/documentation/null-converted-am…
fivetran-avinash Apr 19, 2024
4050c94
using_to_subsidiary default false
fivetran-catfritz Apr 19, 2024
082b25c
Merge branch 'release/v0.13.0-apr-2024' into feature/performance-impr…
fivetran-catfritz Apr 22, 2024
ce13866
adjust cols from merge
fivetran-catfritz Apr 22, 2024
015a571
Merge pull request #116 from fivetran/feature/performance-improvements
fivetran-catfritz Apr 22, 2024
35457dc
use local macros
fivetran-catfritz Apr 29, 2024
52c69ce
typo
fivetran-catfritz Apr 29, 2024
b098cff
Merge pull request #119 from fivetran/feature/performance-improvements
fivetran-catfritz Apr 29, 2024
bfd18a4
regen docs
fivetran-catfritz Apr 29, 2024
8e606a8
Update DECISIONLOG.md
fivetran-catfritz Apr 30, 2024
c17a9f3
Update DECISIONLOG.md
fivetran-catfritz Apr 30, 2024
9e35d8c
Update CHANGELOG.md
fivetran-catfritz Apr 30, 2024
b3d9d05
Update CHANGELOG.md
fivetran-catfritz Apr 30, 2024
cc50278
Update DECISIONLOG.md
fivetran-catfritz Apr 30, 2024
1b0bef2
Update CHANGELOG.md
fivetran-catfritz Apr 30, 2024
fb2c586
Update CHANGELOG.md
fivetran-catfritz Apr 30, 2024
a7e9926
Update packages.yml
fivetran-catfritz Apr 30, 2024
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
4 changes: 3 additions & 1 deletion .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export CI_SNOWFLAKE_DBT_WAREHOUSE=$(gcloud secrets versions access latest --secr
export CI_DATABRICKS_DBT_HOST=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_HOST" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_HTTP_PATH=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_HTTP_PATH" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_TOKEN=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_TOKEN" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_CATALOG=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_CATALOG" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_CATALOG=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_CATALOG" --project="dbt-package-testing-363917")
export CI_DATABRICKS_SQL_DBT_HTTP_PATH=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_SQL_DBT_HTTP_PATH" --project="dbt-package-testing-363917")
export CI_DATABRICKS_SQL_DBT_TOKEN=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_SQL_DBT_TOKEN" --project="dbt-package-testing-363917")
17 changes: 16 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,19 @@ steps:
- "CI_DATABRICKS_DBT_TOKEN"
- "CI_DATABRICKS_DBT_CATALOG"
commands: |
bash .buildkite/scripts/run_models.sh databricks
bash .buildkite/scripts/run_models.sh databricks

- label: ":databricks: :database: Run Tests - Databricks SQL Warehouse"
key: "run_dbt_databricks_sql"
plugins:
- docker#v3.13.0:
image: "python:3.8"
shell: [ "/bin/bash", "-e", "-c" ]
environment:
- "BASH_ENV=/tmp/.bashrc"
- "CI_DATABRICKS_DBT_HOST"
- "CI_DATABRICKS_SQL_DBT_HTTP_PATH"
- "CI_DATABRICKS_SQL_DBT_TOKEN"
- "CI_DATABRICKS_DBT_CATALOG"
commands: |
bash .buildkite/scripts/run_models.sh databricks-sql
22 changes: 22 additions & 0 deletions .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@ db=$1
echo `pwd`
cd integration_tests
dbt deps

if [ "$db" = "databricks-sql" ]; then
dbt seed --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db" --full-refresh
dbt compile --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db"
dbt run --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db" --full-refresh
dbt run --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db"
dbt test --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db"
dbt run --vars '{netsuite_schema: netsuite_integrations_tests_sqlw, netsuite2__using_to_subsidiary: true, netsuite2__multibook_accounting_enabled: true, netsuite2__using_exchange_rate: false, netsuite2__using_vendor_categories: false, netsuite2__using_jobs: false}' --target "$db" --full-refresh
dbt run --vars '{netsuite_schema: netsuite_integrations_tests_sqlw, netsuite2__using_to_subsidiary: true, netsuite2__multibook_accounting_enabled: true, netsuite2__using_exchange_rate: false, netsuite2__using_vendor_categories: false, netsuite2__using_jobs: false}' --target "$db"
dbt test --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db"
dbt run --vars '{netsuite_schema: netsuite_integrations_tests_sqlw, netsuite2__using_to_subsidiary: true, netsuite2__using_exchange_rate: true}' --target "$db" --full-refresh
dbt run --vars '{netsuite_schema: netsuite_integrations_tests_sqlw, netsuite2__using_to_subsidiary: true, netsuite2__using_exchange_rate: true}' --target "$db"
dbt test --vars '{netsuite_schema: netsuite_integrations_tests_sqlw}' --target "$db"

else

dbt seed --target "$db" --full-refresh
dbt compile --target "$db"
dbt run --target "$db" --full-refresh
dbt run --target "$db"
dbt test --target "$db"
dbt run --vars '{netsuite2__using_to_subsidiary: true, netsuite2__multibook_accounting_enabled: true, netsuite2__using_exchange_rate: false, netsuite2__using_vendor_categories: false, netsuite2__using_jobs: false}' --target "$db" --full-refresh
dbt run --vars '{netsuite2__using_to_subsidiary: true, netsuite2__multibook_accounting_enabled: true, netsuite2__using_exchange_rate: false, netsuite2__using_vendor_categories: false, netsuite2__using_jobs: false}' --target "$db"
dbt test --target "$db"
dbt run --vars '{netsuite2__using_to_subsidiary: true, netsuite2__using_exchange_rate: true}' --target "$db" --full-refresh
dbt run --vars '{netsuite2__using_to_subsidiary: true, netsuite2__using_exchange_rate: true}' --target "$db"
dbt test --target "$db"
fi

dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
13 changes: 13 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'auto release'
on:
pull_request:
types:
- closed
branches:
- main

jobs:
call-workflow-passing-data:
if: github.event.pull_request.merged
uses: fivetran/dbt_package_automations/.github/workflows/auto-release.yml@main
secrets: inherit
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# dbt_netsuite v0.13.0
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
[PR #116](https://github.com/fivetran/dbt_netsuite/pull/116) includes the following updates:

## 🚨 Breaking Changes 🚨
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
> ⚠️ Since the following changes are breaking, a `--full-refresh` after upgrading will be required.
- Performance improvements:
- Snowflake, Postgres, and Redshift destinations:
- Added an incremental strategy for the following models:
- `int_netsuite2__tran_with_converted_amounts`
- `netsuite2__balance_sheet`
- `netsuite2__income_statement`
- `netsuite2__transaction_details`
- Bigquery and Databricks destinations:
- Due to the variation in pricing and runtime priorities for customers, by default we chose to materialize these models as tables instead of incremental materialization for Bigquery and Databricks. For more information on this decision, see the [Incremental Strategy section](https://github.com/fivetran/dbt_netsuite/blob/main/DECISIONLOG.md#incremental-strategy) of the DECISIONLOG.
- To enable incremental materialization for these destinations, see the [Incremental Materialization section](https://github.com/fivetran/dbt_netsuite/blob/main/README.md#-adding-incremental-materialization-for-bigquery-and-databricks) of the README for instructions.

## Features
- Added a default 3-day look-back to incremental models to accommodate late arriving records, based on the `_fivetran_synced_date` of transaction records. The number of days can be changed by setting the var `lookback_window` in your dbt_project.yml. See the [Lookback Window section of the README](https://github.com/fivetran/dbt_netsuite/blob/main/README.md#lookback-window) for more details.

## Under the Hood:
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
- Added integration testing pipeline for Databricks SQL Warehouse.
- Included auto-releaser GitHub Actions workflow to automate future releases.

[PR #114](https://github.com/fivetran/dbt_netsuite/pull/114) includes the following updates:

## 🎉 Features
- Added the following columns to model `netsuite2__transaction_details`:
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
- department_id
- entity_id
- is_closed
- is_main_line
- is_tax_line
- item_id
- transaction_number

## 📝 Documentation Update 📝
- [Updated DECISIONLOG](https://github.com/fivetran/dbt_netsuite/blob/main/DECISIONLOG.md#why-converted-transaction-amounts-are-null-if-they-are-non-posting) with our reasoning for why we don't bring in future-facing transactions and leave the `converted_amount` in transaction details empty. ([#115](https://github.com/fivetran/dbt_netsuite/issues/115))
## Contributors:
- [@FrankTub](https://github.com/FrankTub) ([#114](https://github.com/fivetran/dbt_netsuite/issues/114))
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved

# dbt_netsuite v0.12.0
## 🎁 Official release for Netsuite2! 🎁
[PR #98](https://github.com/fivetran/dbt_netsuite/pull/98) is the official supported release of [dbt_netsuite v0.12.0-b1](https://github.com/fivetran/dbt_netsuite/releases/tag/v0.12.0-b1).
Expand Down
18 changes: 17 additions & 1 deletion DECISIONLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ In the `int_netsuite__transactions_with_converted_amounts` model, account types

## Creation of 'Other' Account Category for Non Posting and Statistical Account Types

As mentioned above, in the `int_netsuite__transactions_with_converted_amounts`/`int_netsuite2_tran_with_converted_amounts` models, account types are bucketed into broader account _categories_. There is no standard category for `Non Posting` and `Statistical` account types and transactions from these kinds of accounts are excluded from all financial reports. However, they are used for other workflows in Netsuite, so we have bucketed `Non Posting` and `Statistical` account types into a new `Other` account category.
As mentioned above, in the `int_netsuite__transactions_with_converted_amounts`/`int_netsuite2_tran_with_converted_amounts` models, account types are bucketed into broader account _categories_. There is no standard category for `Non Posting` and `Statistical` account types and transactions from these kinds of accounts are excluded from all financial reports. However, they are used for other workflows in Netsuite, so we have bucketed `Non Posting` and `Statistical` account types into a new `Other` account category.

## Why converted transaction amounts are null if they are non-posting

In our `intermediate` Netsuite models, we translate amounts from posted transactions into their proper `converted_amount` values based on the exchange rates in the reporting and transaction periods. That way, customers will always have accurate `converted_amount` data that can help them validate their financial reporting.

For the sake of financial fidelity, we decided not to convert amounts that are non-posting because the exchange rates are subject to change. While that can provide additional value for customers looking to do financial forecasting, we do not want to create confusion by bringing in converted transactions that have amounts that are variable to change, and disrupt existing financial reporting processes.

For customers interested in creating future-facing `converted_amount` values, our recommendation would be to materialize the `intermediate` tables to grab the exchange rate data in your internal warehouse, then leverage the `transaction_amount` in these particular cases to produce the future `converted_amounts`.
Copy link
Contributor

Choose a reason for hiding this comment

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

"our recommendation would be to materialize the intermediate tables"

Are these currently ephemeral by default and we are suggesting customers materialize them as tables or views? if so, i'd update this wording to be "our recommendation would be to materialize the intermediate models as views or tables (they are currently ephemeral by default)..."

or better yet, it could be good to provide the dbt_project.yml code snippet for how to do so ^

Copy link
Contributor Author

@fivetran-catfritz fivetran-catfritz Apr 30, 2024

Choose a reason for hiding this comment

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

@fivetran-avinash Could you take a look at Jamie's comment since this is related to your PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @fivetran-jamie! I agree with your suggestions.

@fivetran-catfritz

The code snippet they would want to update in the dbt_project.yml would be underneath models, so something like:

For customers interested in creating future-facing converted_amount values, our recommendation would be to materialize the intermediate tables to grab the exchange rate data in your internal warehouse, then leverage the transaction_amount in these particular cases to produce the future converted_amounts. You can update the models section of your dbt_project.yml to update the materialization.

    netsuite2:
      intermediate:
        +materialized: [table or view]

Should suffice to add in the DECISIONLOG.

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!


## Incremental Strategy Selection

For incremental models, we have chosen the `delete+insert` strategy for PostgreSQL, Redshift, and Snowflake destinations.

For Bigquery and Databricks, we have turned off incremental strategy by default since we did not want to cause unexpected warehouse costs for users. If you choose to enable the incremental materialization for these destinations, we have set it up to use the `merge` strategy.
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved

These strategies were selected since transaction records can be updated retroactively, and `merge` and `delete+insert` work well since they rely on a unique id to identify records to update or replace.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Include the following netsuite package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/netsuite
version: [">=0.12.0", "<0.13.0"]
version: [">=0.13.0", "<0.14.0"]
```
## Step 3: Define Netsuite.com or Netsuite2 Source
As of April 2022 Fivetran made available a new Netsuite connector which leverages the Netsuite2 endpoint opposed to the original Netsuite.com endpoint. This package is designed to run for either or, not both. By default the `netsuite_data_model` variable for this package is set to the original `netsuite` value which runs the netsuite.com version of the package. If you would like to run the package on Netsuite2 data, you may adjust the `netsuite_data_model` variable to run the `netsuite2` version of the package.
Expand Down Expand Up @@ -232,6 +232,36 @@ vars:
### Override the data models variable
This package is designed to run **either** the Netsuite.com or Netsuite2 data models. However, for documentation purposes, an additional variable `netsuite_data_model_override` was created to allow for both data model types to be run at the same time by setting the variable value to `netsuite`. This is only to ensure the [dbt docs](https://fivetran.github.io/dbt_netsuite/) (which is hosted on this repository) is generated for both model types. While this variable is provided, we recommend you do not adjust the variable and instead change the `netsuite_data_model` variable to fit your configuration needs.

### Lookback Window
Records from the source can sometimes arrive late. Since several of the models in this package are incremental, by default we look back 3 days from the `_fivetran_synced_date` of transaction records to ensure late arrivals are captured and avoiding the need for frequent full refreshes. While the frequency can be reduced, we still recommend running `dbt --full-refresh` periodically to maintain data quality of the models.

To change the default lookback window, add the following variable to your `dbt_project.yml` file:

```yml
vars:
netsuite:
lookback_window: number_of_days # default is 3
```

### Adding incremental materialization for Bigquery and Databricks
Since pricing and runtime priorities vary by customer, by default we chose to materialize the below models as tables instead of an incremental materialization for Bigquery and Databricks. For more information on this decision, see the [Incremental Strategy section](https://github.com/fivetran/dbt_netsuite/blob/main/DECISIONLOG.md#incremental-strategy) of the DECISIONLOG.

If you wish to enable incremental materializations leveraging the `merge` strategy, you can add the below materialization settings to your `dbt_project.yml` file. You only need to add lines for the specific model materializations you wish to change.
```yml
models:
netsuite:
netsuite2:
netsuite2__income_statement:
+materialized: incremental # default is table for Bigquery and Databricks
netsuite2__transaction_details:
+materialized: incremental # default is table for Bigquery and Databricks
netsuite2__balance_sheet:
+materialized: incremental # default is table for Bigquery and Databricks
intermediate:
int_netsuite2__tran_with_converted_amounts:
+materialized: incremental # default is ephemeral for Bigquery and Databricks
```

## (Optional) Step 7: Produce Analytics-Ready Reports with Streamlit App (Bigquery and Snowflake users only)
For those who want to take their reports a step further, our team has created the [Fivetran Netsuite Streamlit App](https://fivetran-netsuite.streamlit.app/) to generate end model visualizations based off of the reports we created in this package. This way you can replicate much of the reporting you see internally in Netsuite and automate a lot of the work needed to report on your core metrics.

Expand All @@ -252,7 +282,7 @@ This dbt package is dependent on the following dbt packages. Please be aware tha
```yml
packages:
- package: fivetran/netsuite_source
version: [">=0.9.0", "<0.10.0"]
version: [">=0.10.0", "<0.11.0"]

- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
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.12.0'
version: '0.13.0'
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.

4 changes: 2 additions & 2 deletions docs/index.html

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.

8 changes: 8 additions & 0 deletions integration_tests/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ integration_tests:
schema: netsuite_integration_tests_5
threads: 2
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
databricks-sql:
catalog: "{{ env_var('CI_DATABRICKS_DBT_CATALOG') }}"
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
http_path: "{{ env_var('CI_DATABRICKS_SQL_DBT_HTTP_PATH') }}"
schema: netsuite_integrations_tests_sqlw
threads: 8
token: "{{ env_var('CI_DATABRICKS_SQL_DBT_TOKEN') }}"
type: databricks
6 changes: 4 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: 'netsuite_integration_tests'
version: '0.12.0'
version: '0.13.0'
profile: 'integration_tests'
config-version: 2

models:
+materialized: table
+schema: "{{ 'netsuite_integrations_tests_sqlw' if target.name == 'databricks-sql' else 'netsuite' }}"

vars:
netsuite_schema: netsuite_integration_tests_5
netsuite_data_model_override: netsuite
Expand Down
18 changes: 18 additions & 0 deletions macros/netsuite_lookback.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% macro netsuite_lookback(from_date, datepart, interval, safety_date='2010-01-01') %}

{{ adapter.dispatch('netsuite_lookback', 'netsuite') (from_date, datepart, interval, safety_date='2010-01-01') }}

{%- endmacro %}

{% macro default__netsuite_lookback(from_date, datepart, interval, safety_date='2010-01-01') %}

{% set sql_statement %}
select coalesce({{ from_date }}, {{ "'" ~ safety_date ~ "'" }})
from {{ this }}
{%- endset -%}

{%- set result = dbt_utils.get_single_value(sql_statement) %}

{{ dbt.dateadd(datepart=datepart, interval=-interval, from_date_or_timestamp="cast('" ~ result ~ "' as date)") }}

{% endmacro %}
23 changes: 21 additions & 2 deletions models/netsuite2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ models:
tests:
- unique
- not_null
- name: _fivetran_synced_date
description: _fivetran_synced formatted as a date for incremental logic use.

- name: netsuite2__income_statement
description: >
Expand Down Expand Up @@ -176,7 +178,8 @@ models:
tests:
- unique
- not_null

- name: _fivetran_synced_date
description: _fivetran_synced formatted as a date for incremental logic use.

- name: netsuite2__transaction_details
description: >
Expand Down Expand Up @@ -303,4 +306,20 @@ models:
description: Surrogate key hashed on `transaction_line_id` and `transaction_id`. Adds `to_subsidiary_id` if using subsidiaries and `accounting_book_id` if using multibook accounting.
tests:
- unique
- not_null
- not_null
- name: _fivetran_synced_date
description: _fivetran_synced formatted as a date for incremental logic use.
- name: department_id
description: "{{ doc('department_id') }}"
- name: entity_id
description: "{{ doc('entity_id') }}"
- name: is_closed
description: Boolean indicating if the accounting period is closed.
- name: is_main_line
description: Boolean indicating if the transaction line is a main line entry.
- name: is_tax_line
description: Boolean indicating if the transaction line is a tax line..
- name: item_id
description: "{{ doc('item_id') }}"
- name: transaction_number
description: The Netsuite generated number of the transaction.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ transaction_lines_w_accounting_period as ( -- transaction line totals, by accoun
{% endif %}

transactions.accounting_period_id as transaction_accounting_period_id,
coalesce(transaction_lines.amount, 0) as unconverted_amount
coalesce(transaction_lines.amount, 0) as unconverted_amount,
transactions._fivetran_synced_date
from transaction_lines

join transactions on transactions.transaction_id = transaction_lines.transaction_id
Expand Down
Loading