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/add department #82

Merged
merged 12 commits into from
Apr 19, 2023
Merged
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# dbt_quickbooks v0.9.0

## Additional Features
- Added `department_id` to the `quickbooks__general_ledger` and the upstream tables required for that change. ([#63](https://github.com/fivetran/dbt_quickbooks/pull/63))
- Please note that this field was not added to the downstream `quickbooks__general_ledger_by_period`, `quickbooks__balance_sheet`, `quickbooks__profit_and_loss`, or `quickbooks__cash_flow_statement` models as this would require the grain of these models to be adjusted for the `department_id`. This would likely cause more confusion in the initial output. As such, the field was omitted in the aggregate models to ensure consistency of these models. If you wish this to be included, please open a Feature Request to let us know!
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved

## Contributors
- [@MarcelloMolinaro](https://github.com/MarcelloMolinaro) ([#63](https://github.com/fivetran/dbt_quickbooks/pull/63))

## Complimentary Release Notes
- See the source package [CHANGELOG](https://github.com/fivetran/dbt_quickbooks_source/blob/main/CHANGELOG.md) for updates made to the staging layer in `dbt_quickbooks_source v0.8.0`.
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved

# dbt_quickbooks v0.8.1

## 🐛 Bug Fixes 🔨
- Adding partitions by `class_id` in appropriate models to ensure correct account amount aggregations in `quickbooks__general_ledger`, `quickbooks__general_ledger_by_period`, `quickbooks__balance_sheet`, and `quickbooks__profit_and_loss` models. ([#77](https://github.com/fivetran/dbt_quickbooks/pull/77))
- Modifying join in `int_quickbooks__general_ledger_balances` to account for null `class_id` values and bring in the correct non-zero balances. ([#77](https://github.com/fivetran/dbt_quickbooks/pull/77))


# dbt_quickbooks v0.8.0
## 🚨 Breaking Changes 🚨
- Replacing `account_name` with `account_id` as input for the `generate_surrogate_key` function to fix `unique_id` uniqueness issues in the `quickbooks__general_ledger` model. A full refresh is recommended for accurate and consistent surrogate keys. ([#73](https://github.com/fivetran/dbt_quickbooks/pull/73))
Expand Down Expand Up @@ -65,6 +79,8 @@
- Addition of the `credit_card_payment_txn` (enabled/disabled using the `using_credit_card_payment_txn` variable) source as well as the accompanying staging and intermediate models. This source includes all credit card payment transactions and will be used in downstream General Ledger generation to ensure accurate reporting of all transaction types. ([#61](https://github.com/fivetran/dbt_quickbooks/pull/61))
>**Note**: the `credit_card_payment_txn` source and models are disabled by default. In order to enable them, you will want to set the `using_credit_card_payment_txn` variable to `true` in your dbt_project.yml.

- Added `department_id` to the `quickbooks__general_ledger` and the upstream tables required for that change.
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved

## Contributors
- [@mikerenderco](https://github.com/mikerenderco) ([#50](https://github.com/fivetran/dbt_quickbooks/pull/50), [#47](https://github.com/fivetran/dbt_quickbooks/issues/47))
- [@mel-restori](https://github.com/mel-restori) ([#54](https://github.com/fivetran/dbt_quickbooks/pull/54), [#47](https://github.com/fivetran/dbt_quickbooks/issues/47))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<img src="https://img.shields.io/badge/Fivetran_Quickstart_Compatible%3F-yes-green.svg" /></a>
</p>

# QuickBooks dbt Package ([Docs](https://fivetran.github.io/dbt_quickbooks/))
# QuickBooks dbt Package ([Docs](https://fivetran.github.io/dbt_quickbooks/))

# 📖 Table of Contents
- [📣 What does this dbt package do?](https://github.com/fivetran/dbt_quickbooks/#-what-does-this-dbt-package-do)
Expand Down Expand Up @@ -71,7 +71,7 @@ Include the following QuickBooks package version in your `packages.yml` file.
```yaml
packages:
- package: fivetran/quickbooks
version: [">=0.8.0", "<0.9.0"]
version: [">=0.9.0", "<0.10.0"]
```

## Step 3: Define database and schema variables
Expand Down Expand Up @@ -215,7 +215,7 @@ This dbt package is dependent on the following dbt packages. Please be aware tha
```yml
packages:
- package: fivetran/quickbooks_source
version: [">=0.7.0", "<0.8.0"]
version: [">=0.8.0", "<0.9.0"]

- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
Expand Down
1 change: 1 addition & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ config-version: 2
name: 'quickbooks'

version: '0.9.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.

6 changes: 3 additions & 3 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'quickbooks_integration_tests'

version: '0.9.0'
version: '0.9.0'

profile: 'integration_tests'
config-version: 2
Expand All @@ -16,7 +16,7 @@ models:
quickbooks_source:
+materialized: table
tmp:
+materialized: view
+materialized: view
vars:
quickbooks_source:
quickbooks_schema: quickbooks_integrations_tests
Expand Down Expand Up @@ -56,7 +56,7 @@ vars:
quickbooks_refund_receipt_identifier: "refund_receipt_data"
quickbooks_sales_receipt_line_identifier: "sales_receipt_line_data"
quickbooks_sales_receipt_identifier: "sales_receipt_data"
quickbooks_transfer_identifier: "transfer_data"
quickbooks_transfer_identifier: "transfer_data"
quickbooks_vendor_credit_line_identifier: "vendor_credit_line_data"
quickbooks_vendor_credit_identifier: "vendor_credit_data"
quickbooks_vendor_identifier: "vendor_data"
Expand Down
20 changes: 10 additions & 10 deletions integration_tests/seeds/bill_data.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
id,_fivetran_deleted,_fivetran_synced,balance,created_at,currency_id,department_id,doc_number,due_date,exchange_rate,global_tax_calculation,home_balance,payable_account_id,private_note,sales_term_id,sync_token,total_amount,transaction_date,updated_at,vendor_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Already taken care of, but just for reference, commented that source seed files should also be updated but taken care of!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Source updated! Thanks for calling out.

19,TRUE,2020-06-23 3:58:57,1069,2020-05-19 20:48:23,USD,,,,,,,,,,,588,,2020-05-20 12:36:09,
17,TRUE,2020-06-23 3:58:57,992,2020-05-19 20:43:56,USD,,,,,,,,,,,974,,2020-05-22 16:39:03,
15,TRUE,2020-06-23 3:58:57,800,2020-05-19 20:40:52,USD,,,,,,,,,,,386,,2020-06-05 20:14:19,
14,TRUE,2020-06-23 3:58:57,572,2020-05-19 20:25:52,USD,,,,,,,,,,,666,,2020-06-05 20:14:12,
16,TRUE,2020-06-23 3:58:57,737,2020-05-19 20:41:52,USD,,,,,,,,,,,878,,2020-05-19 20:41:55,
18,TRUE,2020-06-23 3:58:57,213,2020-05-19 20:45:15,USD,,,,,,,,,,,946,,2020-05-22 16:40:28,
398,FALSE,2020-12-17 19:32:00,52,2020-12-17 19:21:21,USD,,,2020-12-17,,,,37,,,0,822,2020-12-17,2020-12-17 19:21:21,20
399,FALSE,2020-12-17 19:32:00,991,2020-12-17 19:28:35,USD,,2021-01-01,2020-12-17,,,,37,4e607e75b05d403ca078f850ccab9518,,0,647,2020-12-17,2020-12-17 19:28:35,6
397,FALSE,2020-12-17 19:31:59,832,2020-12-17 19:21:02,USD,,,2020-12-17,,,,37,,,0,757,2020-12-17,2020-12-17 19:21:02,20
401,FALSE,2020-12-17 19:32:00,454,2020-12-17 19:30:30,USD,,2021-03-01,2020-12-17,,,,37,6b681d0cbc9eeb22c903ccedfc47fe17,,0,485,2020-12-17,2020-12-17 19:30:30,6
19,TRUE,2020-06-23 3:58:57,1069,2020-05-19 20:48:23,USD,1,,,,,,,,,,588,,2020-05-20 12:36:09,
17,TRUE,2020-06-23 3:58:57,992,2020-05-19 20:43:56,USD,1,,,,,,,,,,974,,2020-05-22 16:39:03,
15,TRUE,2020-06-23 3:58:57,800,2020-05-19 20:40:52,USD,1,,,,,,,,,,386,,2020-06-05 20:14:19,
14,TRUE,2020-06-23 3:58:57,572,2020-05-19 20:25:52,USD,1,,,,,,,,,,666,,2020-06-05 20:14:12,
16,TRUE,2020-06-23 3:58:57,737,2020-05-19 20:41:52,USD,1,,,,,,,,,,878,,2020-05-19 20:41:55,
18,TRUE,2020-06-23 3:58:57,213,2020-05-19 20:45:15,USD,1,,,,,,,,,,946,,2020-05-22 16:40:28,
398,FALSE,2020-12-17 19:32:00,52,2020-12-17 19:21:21,USD,1,,2020-12-17,,,,37,,,0,822,2020-12-17,2020-12-17 19:21:21,20
399,FALSE,2020-12-17 19:32:00,991,2020-12-17 19:28:35,USD,1,2021-01-01,2020-12-17,,,,37,4e607e75b05d403ca078f850ccab9518,,0,647,2020-12-17,2020-12-17 19:28:35,6
397,FALSE,2020-12-17 19:31:59,832,2020-12-17 19:21:02,USD,1,,2020-12-17,,,,37,,,0,757,2020-12-17,2020-12-17 19:21:02,20
401,FALSE,2020-12-17 19:32:00,454,2020-12-17 19:30:30,USD,1,2021-03-01,2020-12-17,,,,37,6b681d0cbc9eeb22c903ccedfc47fe17,,0,485,2020-12-17,2020-12-17 19:30:30,6
20 changes: 10 additions & 10 deletions integration_tests/seeds/purchase_data.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
id,_fivetran_deleted,_fivetran_synced,account_id,created_at,credit,currency_id,customer_id,department_id,doc_number,employee_id,exchange_rate,global_tax_calculation,payment_method_id,payment_type,print_status,private_note,remit_to_address_id,sync_token,tax_code_id,total_amount,total_tax,transaction_date,transaction_source,updated_at,vendor_id
107,false,2020-12-30 15:02:20,,2020-11-06 1:19:33,,USD,,,,,,,,CreditCard,,,,,,,,2020-11-06 1:19:33,,2020-11-06 1:19:33,18
101,false,2020-12-30 15:02:20,,2020-11-06 1:24:25,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:24:25,18
103,false,2020-12-30 15:02:20,,2020-11-06 1:18:27,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:27,18
232,false,2020-09-01 21:02:33,,2020-07-15 20:03:18,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-07-15 20:03:18,18
228,false,2020-12-30 15:02:20,,2020-11-06 1:21:34,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:21:34,18
372,false,2020-12-30 15:02:20,,2020-09-25 3:42:57,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-10-15 14:17:12,18
190,false,2020-12-30 15:02:20,,2020-11-06 1:22:25,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:22:25,18
340,false,2020-12-30 15:02:20,,2020-11-06 1:18:45,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:45,18
342,false,2020-12-30 15:02:20,,2020-11-21 3:21:38,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-12-02 20:19:49,
350,false,2020-12-30 15:02:20,,2020-11-07 1:43:36,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-07 1:43:36,18
107,FALSE,2020-12-30 15:02:20,,2020-11-06 1:19:33,,USD,,1,,,,,,CreditCard,,,,,,,,2020-11-06 1:19:33,,2020-11-06 1:19:33,18
101,FALSE,2020-12-30 15:02:20,,2020-11-06 1:24:25,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:24:25,18
103,FALSE,2020-12-30 15:02:20,,2020-11-06 1:18:27,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:27,18
232,FALSE,2020-09-01 21:02:33,,2020-07-15 20:03:18,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-07-15 20:03:18,18
228,FALSE,2020-12-30 15:02:20,,2020-11-06 1:21:34,,USD,,2,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:21:34,18
372,FALSE,2020-12-30 15:02:20,,2020-09-25 3:42:57,,USD,,2,,,,,,CreditCard,,,,,,,,,,2020-10-15 14:17:12,18
190,FALSE,2020-12-30 15:02:20,,2020-11-06 1:22:25,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:22:25,18
340,FALSE,2020-12-30 15:02:20,,2020-11-06 1:18:45,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:45,18
342,FALSE,2020-12-30 15:02:20,,2020-11-21 3:21:38,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-12-02 20:19:49,
350,FALSE,2020-12-30 15:02:20,,2020-11-07 1:43:36,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-07 1:43:36,18
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ bill_lines as (
),

items as (
select
item.*,

select
item.*,
parent.expense_account_id as parent_expense_account_id,
parent.income_account_id as parent_income_account_id
from {{ ref('stg_quickbooks__item') }} item
Expand All @@ -40,20 +40,21 @@ bill_join as (
bills.payable_account_id,
coalesce(bill_lines.account_expense_customer_id, bill_lines.item_expense_customer_id) as customer_id,
coalesce(bill_lines.item_expense_class_id, bill_lines.account_expense_class_id) as class_id,
bills.vendor_id
bills.vendor_id,
bills.department_id
from bills

inner join bill_lines
on bills.bill_id = bill_lines.bill_id
and bills.source_relation = bill_lines.source_relation
inner join bill_lines
on bills.bill_id = bill_lines.bill_id
and bills.source_relation = bill_lines.source_relation

left join items
on bill_lines.item_expense_item_id = items.item_id
and bill_lines.source_relation = items.source_relation
),

final as (
select
select
transaction_id,
source_relation,
index,
Expand All @@ -63,6 +64,7 @@ final as (
amount,
payed_to_account_id as account_id,
class_id,
department_id,
'debit' as transaction_type,
'bill' as transaction_source
from bill_join
Expand All @@ -79,10 +81,11 @@ final as (
amount,
payable_account_id as account_id,
class_id,
department_id,
'credit' as transaction_type,
'bill' as transaction_source
from bill_join
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ap_accounts as (
select
account_id
from accounts

where account_type = 'Accounts Payable'
and is_active
and not is_sub_account
Expand All @@ -43,15 +43,16 @@ bill_payment_join as (
bill_payments.total_amount as amount,
coalesce(bill_payments.credit_card_account_id,bill_payments.check_bank_account_id) as payment_account_id,
ap_accounts.account_id,
bill_payments.vendor_id
bill_payments.vendor_id,
bill_payments.department_id
from bill_payments

cross join ap_accounts

),

final as (

select
transaction_id,
source_relation,
Expand All @@ -62,6 +63,7 @@ final as (
amount,
payment_account_id as account_id,
cast(null as {{ dbt.type_string() }}) as class_id,
department_id,
'credit' as transaction_type,
'bill payment' as transaction_source
from bill_payment_join
Expand All @@ -78,10 +80,11 @@ final as (
amount,
account_id,
cast(null as {{ dbt.type_string() }}) as class_id,
department_id,
'debit' as transaction_type,
'bill payment' as transaction_source
from bill_payment_join
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ credit_card_payment_prep as (
credit_card_payments.credit_card_account_id,
cast(null as {{ dbt.type_string() }}) as customer_id,
cast(null as {{ dbt.type_string() }}) as vendor_id,
cast(null as {{ dbt.type_string() }}) as class_id
cast(null as {{ dbt.type_string() }}) as class_id,
cast(null as {{ dbt.type_string() }}) as department_id
from credit_card_payments
),

Expand All @@ -40,6 +41,7 @@ final as (
amount,
cast(bank_account_id as {{ dbt.type_string() }}) as account_id,
class_id,
department_id,
'credit' as transaction_type,
'credit card payment' as transaction_source
from credit_card_payment_prep
Expand All @@ -55,7 +57,8 @@ final as (
vendor_id,
amount,
cast(credit_card_account_id as {{ dbt.type_string() }}) as account_id,
class_id,
class_id,
department_id,
'debit' as transaction_type,
'credit card payment' as transaction_source
from credit_card_payment_prep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ credit_memo_join as (
credit_memo_lines.amount,
coalesce(credit_memo_lines.sales_item_account_id, items.income_account_id, items.expense_account_id) as account_id,
credit_memos.customer_id,
coalesce(credit_memo_lines.sales_item_class_id, credit_memo_lines.discount_class_id, credit_memos.class_id) as class_id

coalesce(credit_memo_lines.sales_item_class_id, credit_memo_lines.discount_class_id, credit_memos.class_id) as class_id,
credit_memos.department_id

from credit_memos

inner join credit_memo_lines
Expand All @@ -77,13 +78,14 @@ final as (
amount * -1 as amount,
account_id,
class_id,
department_id,
'credit' as transaction_type,
'credit_memo' as transaction_source
from credit_memo_join

union all

select
select
transaction_id,
source_relation,
index,
Expand All @@ -93,6 +95,7 @@ final as (
amount * -1 as amount,
df_accounts.account_id,
class_id,
department_id,
'debit' as transaction_type,
'credit_memo' as transaction_source
from credit_memo_join
Expand All @@ -101,4 +104,4 @@ final as (
)

select *
from final
from final
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Table that creates a debit record to the specified cash account and a credit record to either undeposited funds or a
Table that creates a debit record to the specified cash account and a credit record to either undeposited funds or a
specific other account indicated in the deposit line.
*/

Expand All @@ -10,7 +10,7 @@ with deposits as (

select *
from {{ ref('stg_quickbooks__deposit') }}
),
),

deposit_lines as (

Expand Down Expand Up @@ -46,14 +46,15 @@ deposit_join as (
deposits.account_id as deposit_to_acct_id,
coalesce(deposit_lines.deposit_account_id, uf_accounts.account_id) as deposit_from_acct_id,
deposit_customer_id as customer_id,
deposit_lines.deposit_class_id as class_id
deposit_lines.deposit_class_id as class_id,
deposits.department_id

from deposits
inner join deposit_lines

inner join deposit_lines
on deposits.deposit_id = deposit_lines.deposit_id
and deposits.source_relation = deposit_lines.source_relation

cross join uf_accounts

),
Expand All @@ -70,6 +71,7 @@ final as (
amount,
deposit_to_acct_id as account_id,
class_id,
department_id,
'debit' as transaction_type,
'deposit' as transaction_source
from deposit_join
Expand All @@ -86,10 +88,11 @@ final as (
amount,
deposit_from_acct_id as account_id,
class_id,
department_id,
'credit' as transaction_type,
'deposit' as transaction_source
from deposit_join
)

select *
from final
from final
Loading