diff --git a/CHANGELOG.md b/CHANGELOG.md index 98d31e6e..bf56f53c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/analysis/quickbooks__balance_sheet.sql b/analysis/quickbooks__balance_sheet.sql index 6aa1d632..0a809637 100644 --- a/analysis/quickbooks__balance_sheet.sql +++ b/analysis/quickbooks__balance_sheet.sql @@ -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 ( @@ -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 \ No newline at end of file +from equity +group by 1 \ No newline at end of file diff --git a/models/double_entry_transactions/int_quickbooks__refund_receipt_double_entry.sql b/models/double_entry_transactions/int_quickbooks__refund_receipt_double_entry.sql index de46887c..473d98dd 100644 --- a/models/double_entry_transactions/int_quickbooks__refund_receipt_double_entry.sql +++ b/models/double_entry_transactions/int_quickbooks__refund_receipt_double_entry.sql @@ -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 ), diff --git a/models/double_entry_transactions/int_quickbooks__sales_receipt_double_entry.sql b/models/double_entry_transactions/int_quickbooks__sales_receipt_double_entry.sql index f6b4420f..d4d2aa0f 100644 --- a/models/double_entry_transactions/int_quickbooks__sales_receipt_double_entry.sql +++ b/models/double_entry_transactions/int_quickbooks__sales_receipt_double_entry.sql @@ -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 ( diff --git a/models/intermediate/int_quickbooks__invoice_join.sql b/models/intermediate/int_quickbooks__invoice_join.sql index 8a3f586d..9fac1834 100644 --- a/models/intermediate/int_quickbooks__invoice_join.sql +++ b/models/intermediate/int_quickbooks__invoice_join.sql @@ -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 ), @@ -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 ), @@ -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 (