Skip to content
This repository was archived by the owner on Mar 1, 2021. It is now read-only.

Commit 796ad6b

Browse files
authored
Merge pull request #3 from fishtown-analytics/fix/do-classes-better
Fix/do classes better
2 parents f204f59 + 5c84568 commit 796ad6b

14 files changed

+119
-109
lines changed

dbt_project.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ models:
1616
quickbooks_general_ledger:
1717
dist: id
1818
sort: txn_date
19-
quickbooks_parent_class_map:
20-
enabled: false # set to true if this quickbooks install uses classes
2119
base:
2220
materialized: ephemeral
23-
quickbooks_classes:
24-
enabled: false # set to true if this quickbooks install uses classes
2521

2622
vars:
2723
"base.accounts" : "quickbooks.quickbooks_accounts"
@@ -46,5 +42,3 @@ models:
4642
"base.vendors" : "quickbooks.quickbooks_vendors"
4743
"level_0_id_field" : "_sdc_level_0_id"
4844
"source_key_id_field" : "_sdc_source_key_id"
49-
uses_classes : "false" # set to true if this quickbooks install uses classes
50-

models/base/quickbooks_bill_lines.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ select
33
id::int,
44
amount,
55
{{ var('source_key_id_field') }} as bill_id,
6-
{% if var('uses_classes') == "true" %}
7-
nullif(accountbasedexpenselinedetail__classref__value::varchar, '')::bigint as class_id,
8-
{% endif %}
6+
nullif(accountbasedexpenselinedetail__classref__value::varchar, '')::bigint as class_id,
97
accountbasedexpenselinedetail__accountref__value::int as account_id
108
from
119
{{ var('base.bills_line') }}

models/base/quickbooks_deposit_lines.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ select
1818
lines._id as id,
1919
lines.deposit_id,
2020
lines.amount,
21-
{% if var('uses_classes') == "true" %}
22-
nullif(lines.depositlinedetail__classref__value::varchar, '')::bigint as class_id,
23-
{% endif %}
21+
nullif(lines.depositlinedetail__classref__value::varchar, '')::bigint as class_id,
2422
nullif(lines.depositlinedetail__accountref__value::varchar, '')::int as account_id,
2523
links.txnid::int as payment_id
2624
from lines

models/base/quickbooks_invoice_lines.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ select
44
amount,
55
description,
66
{{ var('source_key_id_field') }}::int as invoice_id,
7-
{% if var('uses_classes') == "true" %}
8-
nullif(salesitemlinedetail__classref__value::varchar, '')::bigint as class_id,
9-
{% endif %}
7+
nullif(salesitemlinedetail__classref__value::varchar, '')::bigint as class_id,
108
salesitemlinedetail__itemref__value::int as item_id
119
from
1210
{{ var('base.invoices_lines') }}

models/base/quickbooks_journal_lines.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ select
55
amount,
66
description,
77
journalentrylinedetail__accountref__value::integer as account_id,
8-
{% if var('uses_classes') == "true" %}
9-
nullif(journalentrylinedetail__classref__value::varchar, '')::bigint as class_id,
10-
{% endif %}
8+
nullif(journalentrylinedetail__classref__value::varchar, '')::bigint as class_id,
119
journalentrylinedetail__postingtype as posting_type
1210
from
1311
{{ var('base.journal_entries_line') }}

models/base/quickbooks_purchase_lines.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ select
33
id::int,
44
amount,
55
{{ var('source_key_id_field') }}::int as purchase_id,
6-
{% if var('uses_classes') == "true" %}
7-
nullif(accountbasedexpenselinedetail__classref__value::varchar, '')::bigint as class_id,
8-
{% endif %}
6+
nullif(accountbasedexpenselinedetail__classref__value::varchar, '')::bigint as class_id,
97
accountbasedexpenselinedetail__accountref__value::int as account_id
108
from
119
{{ var('base.purchases_line') }}

models/tables/quickbooks_general_ledger.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ with unioned as (
66
amount,
77
account_id,
88
transaction_type::varchar(64),
9-
source::varchar(64)
10-
{% if var('uses_classes') == "true" %}
11-
, class_id
12-
{% endif %}
9+
source::varchar(64),
10+
class_id
1311
from {{ref('quickbooks_bill_transactions')}}
1412

1513
union all

models/transform/quickbooks_bill_transactions.sql

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,31 @@ with bills as (
1313

1414
select bills.id, bills.txn_date, bill_lines.amount,
1515
bill_lines.account_id as payed_to_acct_id,
16-
ap_account_id
17-
{% if var('uses_classes') == "true" %}
18-
, bill_lines.class_id
19-
{% endif %}
16+
ap_account_id,
17+
bill_lines.class_id
2018
from bills
2119
inner join bill_lines on bills.id = bill_lines.bill_id
2220

2321
)
2422

25-
select id, txn_date, amount, payed_to_acct_id as account_id,
26-
'debit'::varchar(16) as transaction_type, 'bill'::varchar(16) as source
27-
{% if var('uses_classes') == "true" %}
28-
, class_id::bigint
29-
{% endif %}
23+
select id,
24+
txn_date,
25+
amount,
26+
payed_to_acct_id as account_id,
27+
'debit'::varchar(16) as transaction_type,
28+
'bill'::varchar(16) as source,
29+
class_id::bigint
3030

3131
from d1
3232

3333
union all
3434

35-
select id, txn_date, amount, ap_account_id,
36-
'credit' as transaction_type, 'bill'
37-
{% if var('uses_classes') == "true" %}
38-
, class_id::bigint
39-
{% endif %}
35+
select
36+
id,
37+
txn_date,
38+
amount,
39+
ap_account_id,
40+
'credit' as transaction_type,
41+
'bill',
42+
class_id::bigint
4043
from d1

models/transform/quickbooks_billpayment_transactions.sql

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ with bill_payments as (
1212
), d1 as (
1313

1414
select
15-
bp.id, bp.txn_date, bpl.amount, payment_account_id, ap.id as ap_id
15+
bp.id,
16+
bp.txn_date,
17+
bpl.amount,
18+
payment_account_id,
19+
ap.id as ap_id
1620
from bill_payments bp
1721
inner join billpayment_lines bpl on bp.id = bpl.bill_payment_id
1822
join (select id from {{ref('quickbooks_accounts')}} where type = 'Accounts Payable') ap
@@ -21,21 +25,25 @@ with bill_payments as (
2125
)
2226

2327
select
24-
id, txn_date, amount, payment_account_id as account_id, 'credit' as transaction_type,
25-
'bill payment' as source
26-
{% if var('uses_classes') == "true" %}
27-
, null::bigint as class_id
28-
{% endif %}
28+
id,
29+
txn_date,
30+
amount,
31+
payment_account_id as account_id,
32+
'credit' as transaction_type,
33+
'bill payment' as source,
34+
null::bigint as class_id
2935
from
3036
d1
3137

3238
union all
3339

3440
select
35-
id, txn_date, amount, ap_id, 'debit', 'bill payment'
36-
37-
{% if var('uses_classes') == "true" %}
38-
, null::bigint
39-
{% endif %}
41+
id,
42+
txn_date,
43+
amount,
44+
ap_id,
45+
'debit',
46+
'bill payment',
47+
null::bigint
4048
from
4149
d1

models/transform/quickbooks_deposit_transactions.sql

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,38 @@ with lines as (
1111

1212
), d1 as (
1313

14-
select deposits.id, deposits.txn_date, lines.amount,
14+
select
15+
deposits.id,
16+
deposits.txn_date,
17+
lines.amount,
1518
deposits.account_id as deposit_to_acct_id,
16-
coalesce(lines.account_id, udf.id) as deposit_from_acct_id
17-
{% if var('uses_classes') == "true" %}
18-
, lines.class_id
19-
{% endif %}
20-
19+
coalesce(lines.account_id, udf.id) as deposit_from_acct_id,
20+
lines.class_id
2121
from deposits
2222
inner join lines on deposits.id = lines.deposit_id
2323
join (select id from {{ref('quickbooks_accounts')}} where subtype = 'UndepositedFunds') udf
2424
on 1 = 1
2525

2626
)
2727

28-
select id, txn_date, amount, deposit_to_acct_id as account_id,
29-
'debit' as transaction_type, 'deposit' as source
30-
{% if var('uses_classes') == "true" %}
31-
, class_id
32-
{% endif %}
28+
select
29+
id,
30+
txn_date,
31+
amount,
32+
deposit_to_acct_id as account_id,
33+
'debit' as transaction_type,
34+
'deposit' as source,
35+
class_id
3336
from d1
3437

3538
union all
3639

37-
select id, txn_date, amount, deposit_from_acct_id, 'credit', 'deposit'
38-
{% if var('uses_classes') == "true" %}
39-
, class_id
40-
{% endif %}
40+
select
41+
id,
42+
txn_date,
43+
amount,
44+
deposit_from_acct_id,
45+
'credit',
46+
'deposit',
47+
class_id
4148
from d1

0 commit comments

Comments
 (0)