Skip to content

Commit

Permalink
Merge pull request #121 from MatteyRitch/main
Browse files Browse the repository at this point in the history
fixes #120 - missing source_relation joins
  • Loading branch information
fivetran-reneeli authored Apr 24, 2024
2 parents 9d108b1 + b8bd953 commit cdadc65
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# dbt_quickbooks v0.12.3
[PR #120](https://github.com/fivetran/dbt_quickbooks/pull/120) includes the following updates:

## Bug Fixes
- Updated sql models `int_quickbooks__invoice_join`, `int_quickbooks__refund_receipt_double_entry`, `int_quickbooks__sales_receipt_double_entry`, along with the `quickbooks__balance_sheet` analysis sql model to account for the missing `source_relaion` fields and joins that can cause cross-joins when an id is duplicated between sources.

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

Expand Down
18 changes: 12 additions & 6 deletions analysis/quickbooks__balance_sheet.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,37 @@ with general_ledger_by_period as (
liability_date as (
select
account_id,
source_relation,
max(period_first_day) as period_first_day
from general_ledger_by_period

where account_class = 'Liability'

group by 1
group by 1,2
),

asset_date as (
select
account_id,
source_relation,
max(period_first_day) as period_first_day
from general_ledger_by_period

where account_class = 'Asset'

group by 1
group by 1,2
),

equity_date as (
select
account_id,
source_relation,
max(period_first_day) as period_first_day
from general_ledger_by_period

where account_class = 'Equity'

group by 1
group by 1,2
),

liability as (
Expand Down Expand Up @@ -68,20 +71,23 @@ equity as (
)

select
"liability" as balance_sheet_type,
'liability' as balance_sheet_type,
sum(period_ending_balance) as balance
from liability
group by 1

union all

select
"asset" as balance_sheet_type,
'asset' as balance_sheet_type,
sum(period_ending_balance) as balance
from asset
group by 1

union all

select
'equity' as balance_sheet_type,
sum(period_ending_balance) as balance
from equity
from equity
group by 1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ refund_receipt_join as (

left join items
on refund_receipt_lines.sales_item_item_id = items.item_id
and refund_receipt_lines.source_relation = items.source_relation

where coalesce(refund_receipt_lines.discount_account_id, refund_receipt_lines.sales_item_account_id, refund_receipt_lines.sales_item_item_id) is not null
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ items as (

left join {{ ref('stg_quickbooks__item') }} parent
on item.parent_item_id = parent.item_id
and item.source_relation = parent.source_relation
),

sales_receipt_join as (
Expand Down
10 changes: 8 additions & 2 deletions models/intermediate/int_quickbooks__invoice_join.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ invoice_est as (

select
invoices.invoice_id,
invoice_linked.estimate_id
invoice_linked.estimate_id,
invoices.source_relation
from invoices

left join invoice_linked
on invoices.invoice_id = invoice_linked.invoice_id
and invoices.source_relation = invoice_linked.source_relation

where invoice_linked.estimate_id is not null
),
Expand All @@ -52,11 +54,13 @@ invoice_pay as (

select
invoices.invoice_id,
invoice_linked.payment_id
invoice_linked.payment_id,
invoices.source_relation
from invoices

left join invoice_linked
on invoices.invoice_id = invoice_linked.invoice_id
and invoices.source_relation = invoice_linked.source_relation

where invoice_linked.payment_id is not null
),
Expand All @@ -71,9 +75,11 @@ invoice_link as (

left join invoice_est
on invoices.invoice_id = invoice_est.invoice_id
and invoices.source_relation = invoice_est.source_relation

left join invoice_pay
on invoices.invoice_id = invoice_pay.invoice_id
and invoices.source_relation = invoice_pay.source_relation
),

final as (
Expand Down

0 comments on commit cdadc65

Please sign in to comment.