Skip to content

Commit f28eda3

Browse files
Merge pull request #63 from MozartData/MarcelloMolinaro/adds-department_id
Adds department id to general ledger
2 parents 06c29c5 + 11885d2 commit f28eda3

18 files changed

+134
-91
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# dbt_quickbooks v0.8.1
2+
## Additional Features
3+
- 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))
4+
5+
## Contributors
6+
- [@MarcelloMolinaro](https://github.com/MarcelloMolinaro) ([#63](https://github.com/fivetran/dbt_quickbooks/pull/63))
7+
18
# dbt_quickbooks v0.8.0
29
## 🚨 Breaking Changes 🚨
310
- 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))
@@ -60,6 +67,8 @@
6067
- 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))
6168
>**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.
6269
70+
- Added `department_id` to the `quickbooks__general_ledger` and the upstream tables required for that change.
71+
6372
## Contributors
6473
- [@mikerenderco](https://github.com/mikerenderco) ([#50](https://github.com/fivetran/dbt_quickbooks/pull/50), [#47](https://github.com/fivetran/dbt_quickbooks/issues/47))
6574
- [@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))

dbt_project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
config-version: 2
22
name: 'quickbooks'
3-
3+
44
version: '0.8.0'
55
require-dbt-version: [">=1.3.0", "<2.0.0"]
66

integration_tests/dbt_project.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ models:
1616
quickbooks_source:
1717
+materialized: table
1818
tmp:
19-
+materialized: view
19+
+materialized: view
2020
vars:
2121
quickbooks_source:
2222
quickbooks_schema: quickbooks_integrations_tests
@@ -56,7 +56,7 @@ vars:
5656
quickbooks_refund_receipt_identifier: "refund_receipt_data"
5757
quickbooks_sales_receipt_line_identifier: "sales_receipt_line_data"
5858
quickbooks_sales_receipt_identifier: "sales_receipt_data"
59-
quickbooks_transfer_identifier: "transfer_data"
59+
quickbooks_transfer_identifier: "transfer_data"
6060
quickbooks_vendor_credit_line_identifier: "vendor_credit_line_data"
6161
quickbooks_vendor_credit_identifier: "vendor_credit_data"
6262
quickbooks_vendor_identifier: "vendor_data"

integration_tests/seeds/bill_data.csv

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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
2-
19,TRUE,2020-06-23 3:58:57,1069,2020-05-19 20:48:23,USD,,,,,,,,,,,588,,2020-05-20 12:36:09,
3-
17,TRUE,2020-06-23 3:58:57,992,2020-05-19 20:43:56,USD,,,,,,,,,,,974,,2020-05-22 16:39:03,
4-
15,TRUE,2020-06-23 3:58:57,800,2020-05-19 20:40:52,USD,,,,,,,,,,,386,,2020-06-05 20:14:19,
5-
14,TRUE,2020-06-23 3:58:57,572,2020-05-19 20:25:52,USD,,,,,,,,,,,666,,2020-06-05 20:14:12,
6-
16,TRUE,2020-06-23 3:58:57,737,2020-05-19 20:41:52,USD,,,,,,,,,,,878,,2020-05-19 20:41:55,
7-
18,TRUE,2020-06-23 3:58:57,213,2020-05-19 20:45:15,USD,,,,,,,,,,,946,,2020-05-22 16:40:28,
8-
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
9-
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
10-
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
11-
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
2+
19,TRUE,2020-06-23 3:58:57,1069,2020-05-19 20:48:23,USD,1,,,,,,,,,,588,,2020-05-20 12:36:09,
3+
17,TRUE,2020-06-23 3:58:57,992,2020-05-19 20:43:56,USD,1,,,,,,,,,,974,,2020-05-22 16:39:03,
4+
15,TRUE,2020-06-23 3:58:57,800,2020-05-19 20:40:52,USD,1,,,,,,,,,,386,,2020-06-05 20:14:19,
5+
14,TRUE,2020-06-23 3:58:57,572,2020-05-19 20:25:52,USD,1,,,,,,,,,,666,,2020-06-05 20:14:12,
6+
16,TRUE,2020-06-23 3:58:57,737,2020-05-19 20:41:52,USD,1,,,,,,,,,,878,,2020-05-19 20:41:55,
7+
18,TRUE,2020-06-23 3:58:57,213,2020-05-19 20:45:15,USD,1,,,,,,,,,,946,,2020-05-22 16:40:28,
8+
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
9+
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
10+
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
11+
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
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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
2-
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
3-
101,false,2020-12-30 15:02:20,,2020-11-06 1:24:25,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:24:25,18
4-
103,false,2020-12-30 15:02:20,,2020-11-06 1:18:27,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:27,18
5-
232,false,2020-09-01 21:02:33,,2020-07-15 20:03:18,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-07-15 20:03:18,18
6-
228,false,2020-12-30 15:02:20,,2020-11-06 1:21:34,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:21:34,18
7-
372,false,2020-12-30 15:02:20,,2020-09-25 3:42:57,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-10-15 14:17:12,18
8-
190,false,2020-12-30 15:02:20,,2020-11-06 1:22:25,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:22:25,18
9-
340,false,2020-12-30 15:02:20,,2020-11-06 1:18:45,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:45,18
10-
342,false,2020-12-30 15:02:20,,2020-11-21 3:21:38,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-12-02 20:19:49,
11-
350,false,2020-12-30 15:02:20,,2020-11-07 1:43:36,,USD,,,,,,,,CreditCard,,,,,,,,,,2020-11-07 1:43:36,18
2+
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
3+
101,FALSE,2020-12-30 15:02:20,,2020-11-06 1:24:25,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:24:25,18
4+
103,FALSE,2020-12-30 15:02:20,,2020-11-06 1:18:27,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:27,18
5+
232,FALSE,2020-09-01 21:02:33,,2020-07-15 20:03:18,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-07-15 20:03:18,18
6+
228,FALSE,2020-12-30 15:02:20,,2020-11-06 1:21:34,,USD,,2,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:21:34,18
7+
372,FALSE,2020-12-30 15:02:20,,2020-09-25 3:42:57,,USD,,2,,,,,,CreditCard,,,,,,,,,,2020-10-15 14:17:12,18
8+
190,FALSE,2020-12-30 15:02:20,,2020-11-06 1:22:25,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:22:25,18
9+
340,FALSE,2020-12-30 15:02:20,,2020-11-06 1:18:45,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-06 1:18:45,18
10+
342,FALSE,2020-12-30 15:02:20,,2020-11-21 3:21:38,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-12-02 20:19:49,
11+
350,FALSE,2020-12-30 15:02:20,,2020-11-07 1:43:36,,USD,,1,,,,,,CreditCard,,,,,,,,,,2020-11-07 1:43:36,18

models/double_entry_transactions/int_quickbooks__bill_double_entry.sql

+12-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ bill_lines as (
1818
),
1919

2020
items as (
21-
22-
select
23-
item.*,
21+
22+
select
23+
item.*,
2424
parent.expense_account_id as parent_expense_account_id,
2525
parent.income_account_id as parent_income_account_id
2626
from {{ ref('stg_quickbooks__item') }} item
@@ -40,20 +40,21 @@ bill_join as (
4040
bills.payable_account_id,
4141
coalesce(bill_lines.account_expense_customer_id, bill_lines.item_expense_customer_id) as customer_id,
4242
coalesce(bill_lines.item_expense_class_id, bill_lines.account_expense_class_id) as class_id,
43-
bills.vendor_id
43+
bills.vendor_id,
44+
bills.department_id
4445
from bills
4546

46-
inner join bill_lines
47-
on bills.bill_id = bill_lines.bill_id
48-
and bills.source_relation = bill_lines.source_relation
47+
inner join bill_lines
48+
on bills.bill_id = bill_lines.bill_id
49+
and bills.source_relation = bill_lines.source_relation
4950

5051
left join items
5152
on bill_lines.item_expense_item_id = items.item_id
5253
and bill_lines.source_relation = items.source_relation
5354
),
5455

5556
final as (
56-
select
57+
select
5758
transaction_id,
5859
source_relation,
5960
index,
@@ -63,6 +64,7 @@ final as (
6364
amount,
6465
payed_to_account_id as account_id,
6566
class_id,
67+
department_id,
6668
'debit' as transaction_type,
6769
'bill' as transaction_source
6870
from bill_join
@@ -79,10 +81,11 @@ final as (
7981
amount,
8082
payable_account_id as account_id,
8183
class_id,
84+
department_id,
8285
'credit' as transaction_type,
8386
'bill' as transaction_source
8487
from bill_join
8588
)
8689

8790
select *
88-
from final
91+
from final

models/double_entry_transactions/int_quickbooks__bill_payment_double_entry.sql

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ap_accounts as (
2828
select
2929
account_id
3030
from accounts
31-
31+
3232
where account_type = 'Accounts Payable'
3333
and is_active
3434
and not is_sub_account
@@ -43,15 +43,16 @@ bill_payment_join as (
4343
bill_payments.total_amount as amount,
4444
coalesce(bill_payments.credit_card_account_id,bill_payments.check_bank_account_id) as payment_account_id,
4545
ap_accounts.account_id,
46-
bill_payments.vendor_id
46+
bill_payments.vendor_id,
47+
bill_payments.department_id
4748
from bill_payments
4849

4950
cross join ap_accounts
5051

5152
),
5253

5354
final as (
54-
55+
5556
select
5657
transaction_id,
5758
source_relation,
@@ -62,6 +63,7 @@ final as (
6263
amount,
6364
payment_account_id as account_id,
6465
cast(null as {{ dbt.type_string() }}) as class_id,
66+
department_id,
6567
'credit' as transaction_type,
6668
'bill payment' as transaction_source
6769
from bill_payment_join
@@ -78,10 +80,11 @@ final as (
7880
amount,
7981
account_id,
8082
cast(null as {{ dbt.type_string() }}) as class_id,
83+
department_id,
8184
'debit' as transaction_type,
8285
'bill payment' as transaction_source
8386
from bill_payment_join
8487
)
8588

8689
select *
87-
from final
90+
from final

models/double_entry_transactions/int_quickbooks__credit_memo_double_entry.sql

+7-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ credit_memo_join as (
5050
credit_memo_lines.amount,
5151
coalesce(credit_memo_lines.sales_item_account_id, items.income_account_id, items.expense_account_id) as account_id,
5252
credit_memos.customer_id,
53-
coalesce(credit_memo_lines.sales_item_class_id, credit_memo_lines.discount_class_id, credit_memos.class_id) as class_id
54-
53+
coalesce(credit_memo_lines.sales_item_class_id, credit_memo_lines.discount_class_id, credit_memos.class_id) as class_id,
54+
credit_memos.department_id
55+
5556
from credit_memos
5657

5758
inner join credit_memo_lines
@@ -77,13 +78,14 @@ final as (
7778
amount * -1 as amount,
7879
account_id,
7980
class_id,
81+
department_id,
8082
'credit' as transaction_type,
8183
'credit_memo' as transaction_source
8284
from credit_memo_join
8385

8486
union all
8587

86-
select
88+
select
8789
transaction_id,
8890
source_relation,
8991
index,
@@ -93,6 +95,7 @@ final as (
9395
amount * -1 as amount,
9496
df_accounts.account_id,
9597
class_id,
98+
department_id,
9699
'debit' as transaction_type,
97100
'credit_memo' as transaction_source
98101
from credit_memo_join
@@ -101,4 +104,4 @@ final as (
101104
)
102105

103106
select *
104-
from final
107+
from final

models/double_entry_transactions/int_quickbooks__deposit_double_entry.sql

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Table that creates a debit record to the specified cash account and a credit record to either undeposited funds or a
2+
Table that creates a debit record to the specified cash account and a credit record to either undeposited funds or a
33
specific other account indicated in the deposit line.
44
*/
55

@@ -10,7 +10,7 @@ with deposits as (
1010

1111
select *
1212
from {{ ref('stg_quickbooks__deposit') }}
13-
),
13+
),
1414

1515
deposit_lines as (
1616

@@ -46,14 +46,15 @@ deposit_join as (
4646
deposits.account_id as deposit_to_acct_id,
4747
coalesce(deposit_lines.deposit_account_id, uf_accounts.account_id) as deposit_from_acct_id,
4848
deposit_customer_id as customer_id,
49-
deposit_lines.deposit_class_id as class_id
49+
deposit_lines.deposit_class_id as class_id,
50+
deposits.department_id
5051

5152
from deposits
52-
53-
inner join deposit_lines
53+
54+
inner join deposit_lines
5455
on deposits.deposit_id = deposit_lines.deposit_id
5556
and deposits.source_relation = deposit_lines.source_relation
56-
57+
5758
cross join uf_accounts
5859

5960
),
@@ -70,6 +71,7 @@ final as (
7071
amount,
7172
deposit_to_acct_id as account_id,
7273
class_id,
74+
department_id,
7375
'debit' as transaction_type,
7476
'deposit' as transaction_source
7577
from deposit_join
@@ -86,10 +88,11 @@ final as (
8688
amount,
8789
deposit_from_acct_id as account_id,
8890
class_id,
91+
department_id,
8992
'credit' as transaction_type,
9093
'deposit' as transaction_source
9194
from deposit_join
9295
)
9396

9497
select *
95-
from final
98+
from final

0 commit comments

Comments
 (0)