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 class to ledger models #58

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# New feature
- Addition of `class_id` to `quickbooks__general_ledger` and `quickbooks_general_ledger_by_period`, add in class values for all intermediate models necessary to pass into final models.
# dbt_quickbooks_source v0.6.0
## 🚨 Breaking Changes 🚨:
[PR #51](https://github.com/fivetran/dbt_quickbooks/pull/51) includes the following breaking changes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ items as (
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
from {{ ref('stg_quickbooks__item') }} item

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

Expand All @@ -35,6 +35,7 @@ bill_join as (
coalesce(bill_lines.account_expense_account_id, items.expense_account_id, items.parent_expense_account_id, items.expense_account_id, items.parent_income_account_id, items.income_account_id) as payed_to_account_id,
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
from bills

Expand All @@ -54,6 +55,7 @@ final as (
vendor_id,
amount,
payed_to_account_id as account_id,
class_id,
'debit' as transaction_type,
'bill' as transaction_source
from bill_join
Expand All @@ -68,6 +70,7 @@ final as (
vendor_id,
amount,
payable_account_id as account_id,
class_id,
'credit' as transaction_type,
'bill' as transaction_source
from bill_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final as (
vendor_id,
amount,
payment_account_id as account_id,
cast(null as {{ dbt.type_string() }}) as class_id,
'credit' as transaction_type,
'bill payment' as transaction_source
from bill_payment_join
Expand All @@ -68,6 +69,7 @@ final as (
vendor_id,
amount,
account_id,
cast(null as {{ dbt.type_string() }}) as class_id,
'debit' as transaction_type,
'bill payment' as transaction_source
from bill_payment_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Table that creates a debit record to the associated bank account and a credit re

with credit_card_payments as (
select *
from {{ref('stg_quickbooks__credit_card_payment_txn')}}
from {{ ref('stg_quickbooks__credit_card_payment_txn') }}
where is_most_recent_record
),

Expand All @@ -20,7 +20,8 @@ credit_card_payment_prep as (
credit_card_payments.bank_account_id,
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 vendor_id,
cast(null as {{ dbt.type_string() }}) as class_id
from credit_card_payments
),

Expand All @@ -33,6 +34,7 @@ final as (
vendor_id,
amount,
credit_card_account_id as account_id,
class_id,
'credit' as transaction_type,
'credit card payment' as transaction_source
from credit_card_payment_prep
Expand All @@ -46,7 +48,8 @@ final as (
customer_id,
vendor_id,
amount,
bank_account_id,
bank_account_id as account_id,
class_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 @@ -7,17 +7,17 @@ Table that creates a debit record to Discounts Refunds Given and a credit record

with credit_memos as (
select *
from {{ref('stg_quickbooks__credit_memo')}}
from {{ ref('stg_quickbooks__credit_memo') }}
),

credit_memo_lines as (
select *
from {{ref('stg_quickbooks__credit_memo_line')}}
from {{ ref('stg_quickbooks__credit_memo_line') }}
),

items as (
select *
from {{ref('stg_quickbooks__item')}}
from {{ ref('stg_quickbooks__item') }}
),

accounts as (
Expand All @@ -42,7 +42,9 @@ credit_memo_join as (
credit_memos.transaction_date,
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
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

from credit_memos

inner join credit_memo_lines
Expand All @@ -63,6 +65,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount * -1 as amount,
account_id,
class_id,
'credit' as transaction_type,
'credit_memo' as transaction_source
from credit_memo_join
Expand All @@ -77,6 +80,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount * -1 as amount,
df_accounts.account_id,
class_id,
'debit' as transaction_type,
'credit_memo' as transaction_source
from credit_memo_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ specific other account indicated in the deposit line.

with deposits as (
select *
from {{ref('stg_quickbooks__deposit')}}
from {{ ref('stg_quickbooks__deposit') }}
),

deposit_lines as (
select *
from {{ref('stg_quickbooks__deposit_line')}}
from {{ ref('stg_quickbooks__deposit_line') }}
),

accounts as (
Expand All @@ -39,7 +39,9 @@ deposit_join as (
deposit_lines.amount,
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_customer_id as customer_id,
deposit_lines.deposit_class_id as class_id

from deposits

inner join deposit_lines
Expand All @@ -58,6 +60,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount,
deposit_to_acct_id as account_id,
class_id,
'debit' as transaction_type,
'deposit' as transaction_source
from deposit_join
Expand All @@ -72,6 +75,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount,
deposit_from_acct_id as account_id,
class_id,
'credit' as transaction_type,
'deposit' as transaction_source
from deposit_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Table that creates a debit record to accounts receivable and a credit record to

with invoices as (
select *
from {{ref('stg_quickbooks__invoice')}}
from {{ ref('stg_quickbooks__invoice') }}
),

invoice_lines as (
select *
from {{ref('stg_quickbooks__invoice_line')}}
from {{ ref('stg_quickbooks__invoice_line') }}
),

items as (
Expand All @@ -32,6 +32,7 @@ accounts as (


{% if var('using_invoice_bundle', True) %}

invoice_bundles as (
select *
from {{ref('stg_quickbooks__invoice_line_bundle')}}
Expand All @@ -43,8 +44,7 @@ bundles as (
),

bundle_items as (
select
*
select *
from {{ref('stg_quickbooks__bundle_item')}}
),

Expand All @@ -58,7 +58,8 @@ income_accounts as (
bundle_income_accounts as (
select distinct
coalesce(parent.income_account_id, income_accounts.account_id) as account_id,
bundle_items.bundle_id
bundle_items.bundle_id

from items

left join items as parent
Expand Down Expand Up @@ -91,11 +92,12 @@ invoice_join as (

{% if var('using_invoice_bundle', True) %}
coalesce(invoice_lines.account_id, items.parent_income_account_id, items.income_account_id, bundle_income_accounts.account_id) as account_id,

{% else %}
coalesce(invoice_lines.account_id, items.income_account_id) as account_id,

{% endif %}

coalesce(invoice_lines.sales_item_class_id, invoice_lines.discount_class_id, invoices.class_id) as class_id,

invoices.customer_id

from invoices
Expand Down Expand Up @@ -127,6 +129,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount,
account_id,
class_id,
'credit' as transaction_type,
'invoice' as transaction_source
from invoice_join
Expand All @@ -141,6 +144,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount,
ar_accounts.account_id,
class_id,
'debit' as transaction_type,
'invoice' as transaction_source
from invoice_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Table that provides the debit and credit records of a journal entry transaction.

with journal_entries as (
select *
from {{ref('stg_quickbooks__journal_entry')}}
from {{ ref('stg_quickbooks__journal_entry') }}
),

journal_entry_lines as (
select *
from {{ref('stg_quickbooks__journal_entry_line')}}
from {{ ref('stg_quickbooks__journal_entry_line') }}
),

final as (
Expand All @@ -24,6 +24,7 @@ final as (
journal_entry_lines.vendor_id,
journal_entry_lines.amount,
journal_entry_lines.account_id,
class_id,
lower(journal_entry_lines.posting_type) as transaction_type,
'journal_entry' as transaction_source
from journal_entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Table that creates a debit record to either undeposited funds or a specified cas

with payments as (
select *
from {{ref('stg_quickbooks__payment')}}
from {{ ref('stg_quickbooks__payment') }}
),

payment_lines as (
select *
from {{ref('stg_quickbooks__payment_line')}}
from {{ ref('stg_quickbooks__payment_line') }}
),

accounts as (
Expand Down Expand Up @@ -51,6 +51,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount,
deposit_to_account_id as account_id,
cast(null as {{ dbt.type_string() }}) as class_id,
'debit' as transaction_type,
'payment' as transaction_source
from payment_join
Expand All @@ -65,6 +66,7 @@ final as (
cast(null as {{ dbt.type_string() }}) as vendor_id,
amount,
coalesce(receivable_account_id, ar_accounts.account_id) as account_id,
cast(null as {{ dbt.type_string() }}) as class_id,
'credit' as transaction_type,
'payment' as transaction_source
from payment_join
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ Table that creates a debit record to a specified expense account and a credit re
*/
with purchases as (
select *
from {{ref('stg_quickbooks__purchase')}}
from {{ ref('stg_quickbooks__purchase') }}
),

purchase_lines as (
select *
from {{ref('stg_quickbooks__purchase_line')}}
from {{ ref('stg_quickbooks__purchase_line') }}
),

items as (
select
item.*,
parent.expense_account_id as parent_expense_account_id
from {{ref('stg_quickbooks__item')}} item
from {{ ref('stg_quickbooks__item') }} item

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

Expand All @@ -32,6 +32,7 @@ purchase_join as (
case when coalesce(purchases.credit, false) = true then 'debit' else 'credit' end as payed_from_transaction_type,
case when coalesce(purchases.credit, false) = true then 'credit' else 'debit' end as payed_to_transaction_type,
purchases.customer_id,
coalesce(purchase_lines.item_expense_class_id, purchase_lines.account_expense_class_id) as class_id,
purchases.vendor_id
from purchases

Expand All @@ -51,6 +52,7 @@ final as (
vendor_id,
amount,
payed_from_account_id as account_id,
class_id,
payed_from_transaction_type as transaction_type,
'purchase' as transaction_source
from purchase_join
Expand All @@ -65,6 +67,7 @@ final as (
vendor_id,
amount,
payed_to_account_id as account_id,
class_id,
payed_to_transaction_type as transaction_type,
'purchase' as transaction_source
from purchase_join
Expand Down
Loading