Skip to content

Commit 33d87ef

Browse files
committed
fix: correct noncash asset signs in cash flow statements
1 parent 3a48f70 commit 33d87ef

11 files changed

Lines changed: 124 additions & 8 deletions

‎DECISIONLOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The corresponding entry that would result from the `int_quickbooks__invoice_doub
3030
- Financing: The movement of cash between a firm and its owners, investors, and creditors. Account types like long term liability and account classes like equity fall here under our logic.
3131
- Cash or Cash Equivalents: Line items that report value of a company's cash assets. Bank account types are assigned here.
3232

33+
- The cash flow statement reverses the signs of noncash Asset balances before calculating monthly changes, for both original and converted amounts. Bank accounts retain their balance-sheet signs. An increase in accounts receivable, prepaid expenses, or fixed assets therefore reduces cash flow; a decrease increases it. Liability and Equity accounts retain their balance-sheet signs.
34+
3335
- While the default case statement logic should work for many customers with basic setups, as customization gets more advanced for your specific business, this is not likely to cover all cases. This is why we created the seed functionality to allow you flexibility to adjust the cash flow types for your own custom purposes--[you can read more about how to set it up in our README](https://github.com/fivetran/dbt_quickbooks/blob/main/README.md#customize-the-cash-flow-model).
3436

3537
## QuickBooks Financial Statement Ordinal Logic

‎docs/catalog.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎docs/manifest.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎integration_tests/seeds/account_data.csv‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ id,_fivetran_synced,account_number,account_sub_type,account_type,active,balance,
4040
94102,2026-02-10 12:00:00,9402,100fb8196b919896e083af2939bbffb3,Accounts Payable,TRUE,0,0,Liability,2026-02-10 00:00:00,GBP,Alternate GBP AP account to simulate multi-account ambiguity,Accounts Payable GBP Alt,Accounts Payable GBP Alt,,FALSE,1,,2026-02-10 12:00:00,FALSE
4141
95001,2021-01-01 12:00:00,4201,SalesOfProductIncome,Income,TRUE,0,0,Revenue,2021-01-01 12:00:00,USD,Product income account for an item in bundle 149,Product Sales,Product Sales,,FALSE,0,,2021-01-01 12:00:00,FALSE
4242
95002,2021-01-01 12:00:00,4202,SalesOfProductIncome,Income,TRUE,0,0,Revenue,2021-01-01 12:00:00,USD,Second product income account so bundle 149 maps to two,Product Sales 2,Product Sales 2,,FALSE,0,,2021-01-01 12:00:00,FALSE
43+
96001,2024-01-01 00:00:00,96001,CashOnHand,Bank,TRUE,0,0,Asset,2024-01-01 00:00:00,EUR,Synthetic cash flow sign regression fixture,Cash flow test bank,Cash flow test bank,,FALSE,0,,2024-01-01 00:00:00,FALSE
44+
96002,2024-01-01 00:00:00,96002,PrepaidExpenses,Other Current Asset,TRUE,0,0,Asset,2024-01-01 00:00:00,EUR,Synthetic cash flow sign regression fixture,Cash flow test prepaid expenses,Cash flow test prepaid expenses,,FALSE,0,,2024-01-01 00:00:00,FALSE
45+
96003,2024-01-01 00:00:00,96003,MachineryAndEquipment,Fixed Asset,TRUE,0,0,Asset,2024-01-01 00:00:00,EUR,Synthetic cash flow sign regression fixture,Cash flow test equipment,Cash flow test equipment,,FALSE,0,,2024-01-01 00:00:00,FALSE
46+
96004,2024-01-01 00:00:00,96004,OtherCurrentLiabilities,Other Current Liability,TRUE,0,0,Liability,2024-01-01 00:00:00,EUR,Synthetic cash flow sign regression fixture,Cash flow test liability,Cash flow test liability,,FALSE,0,,2024-01-01 00:00:00,FALSE
47+
96005,2024-01-01 00:00:00,96005,OwnersEquity,Equity,TRUE,0,0,Equity,2024-01-01 00:00:00,EUR,Synthetic cash flow sign regression fixture,Cash flow test equity,Cash flow test equity,,FALSE,0,,2024-01-01 00:00:00,FALSE
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
account_id,cash_flow_period,cash_flow_type,cash_beginning_period,cash_ending_period,cash_net_period,cash_converted_beginning_period,cash_converted_ending_period,cash_converted_net_period
2+
96001,2024-01-01,Cash or Cash Equivalents,0,1000,1000,0,2000,2000
3+
96001,2024-02-01,Cash or Cash Equivalents,1000,600,-400,2000,1200,-800
4+
96001,2024-03-01,Cash or Cash Equivalents,600,630,30,1200,1260,60
5+
96002,2024-01-01,Operating,0,0,0,0,0,0
6+
96002,2024-02-01,Operating,0,-200,-200,0,-400,-400
7+
96002,2024-03-01,Operating,-200,-150,50,-400,-300,100
8+
96003,2024-01-01,Investing,0,0,0,0,0,0
9+
96003,2024-02-01,Investing,0,-300,-300,0,-600,-600
10+
96003,2024-03-01,Investing,-300,-280,20,-600,-560,40
11+
96004,2024-01-01,Operating,0,0,0,0,0,0
12+
96004,2024-02-01,Operating,0,100,100,0,200,200
13+
96004,2024-03-01,Operating,100,60,-40,200,120,-80
14+
96005,2024-01-01,Financing,0,1000,1000,0,2000,2000
15+
96005,2024-02-01,Financing,1000,1000,0,2000,2000,0
16+
96005,2024-03-01,Financing,1000,1000,0,2000,2000,0

‎integration_tests/seeds/journal_entry_data.csv‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ id,_fivetran_deleted,_fivetran_synced,adjustment,created_at,currency_id,doc_numb
1313
44,FALSE,2020-06-23 03:58:59,FALSE,2020-06-23 03:45:00,USD,93a3c769704fbd2f2e84270cae00f49b,1.0,,5aa72aeaa898300af7bf421fb3568a2d,0,,99205.00,5952.30,2020-06-23,2020-06-23 03:45:00
1414
395,FALSE,2020-12-10 00:02:05,FALSE,2020-12-10 00:00:00,USD,ab0e9618346d8779c343a6782e079723,1.0,,5aa72aeaa898300af7bf421fb3568a2d,0,,62405.00,4680.38,2020-12-10,2020-12-10 00:00:00
1515
9002,FALSE,2026-02-10 12:00:00,FALSE,2026-02-10 12:00:00,GBP,,,,,1,,1500,,2026-02-10,2026-02-10 12:00:00
16-
9003,FALSE,2026-02-10 12:00:00,FALSE,2026-02-10 12:00:00,GBP,,,,,1,,7000,,2026-02-10,2026-02-10 12:00:00
16+
9003,FALSE,2026-02-10 12:00:00,FALSE,2026-02-10 12:00:00,GBP,,,,,1,,7000,,2026-02-10,2026-02-10 12:00:00
17+
96001,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96001,2,2000,Synthetic cash flow sign regression fixture,0,,1000,0,2024-01-15,2024-01-01 00:00:00
18+
96002,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96002,2,400,Synthetic cash flow sign regression fixture,0,,200,0,2024-02-15,2024-01-01 00:00:00
19+
96003,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96003,2,600,Synthetic cash flow sign regression fixture,0,,300,0,2024-02-16,2024-01-01 00:00:00
20+
96004,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96004,2,200,Synthetic cash flow sign regression fixture,0,,100,0,2024-02-17,2024-01-01 00:00:00
21+
96005,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96005,2,100,Synthetic cash flow sign regression fixture,0,,50,0,2024-03-15,2024-01-01 00:00:00
22+
96006,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96006,2,80,Synthetic cash flow sign regression fixture,0,,40,0,2024-03-16,2024-01-01 00:00:00
23+
96007,FALSE,2024-01-01 00:00:00,FALSE,2024-01-01 00:00:00,EUR,cash-flow-signs-96007,2,40,Synthetic cash flow sign regression fixture,0,,20,0,2024-03-17,2024-01-01 00:00:00

‎integration_tests/seeds/journal_entry_line_data.csv‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ index,journal_entry_id,_fivetran_synced,account_id,amount,billable_status,class_
1212
0,92011,2024-01-20 09:00:00,51515,100,,,10,,Test JE to Expense,2024-01-20,,10,Debit,,,,
1313
0,92012,2024-01-20 09:00:00,52525,200,,,10,,Test JE to COGS,2024-01-20,,10,Debit,,,,
1414
0,9002,2026-02-10 12:00:00,92003,1500,,,2150,,,,,,Debit,,,,
15-
0,9003,2026-02-10 12:00:00,20299,7000,,,,,,,,,Credit,,,,
15+
0,9003,2026-02-10 12:00:00,20299,7000,,,,,,,,,Credit,,,,
16+
0,96001,2024-01-01 00:00:00,96001,1000,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
17+
1,96001,2024-01-01 00:00:00,96005,1000,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,
18+
0,96002,2024-01-01 00:00:00,96002,200,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
19+
1,96002,2024-01-01 00:00:00,96001,200,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,
20+
0,96003,2024-01-01 00:00:00,96003,300,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
21+
1,96003,2024-01-01 00:00:00,96001,300,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,
22+
0,96004,2024-01-01 00:00:00,96001,100,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
23+
1,96004,2024-01-01 00:00:00,96004,100,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,
24+
0,96005,2024-01-01 00:00:00,96001,50,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
25+
1,96005,2024-01-01 00:00:00,96002,50,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,
26+
0,96006,2024-01-01 00:00:00,96004,40,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
27+
1,96006,2024-01-01 00:00:00,96001,40,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,
28+
0,96007,2024-01-01 00:00:00,96001,20,,,,,Synthetic cash flow sign regression fixture,,,,Debit,,,,
29+
1,96007,2024-01-01 00:00:00,96003,20,,,,,Synthetic cash flow sign regression fixture,,,,Credit,,,,

‎integration_tests/tests/integrity/cash_flow_amounts_match.sql‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ with balance_sheet as (
77

88
select
99
calendar_date as cash_flow_period,
10-
sum(amount) as period_amount_source,
11-
sum(converted_amount) as period_converted_amount_source
10+
sum(case when account_class = 'Asset' and account_type != 'Bank'
11+
then -amount else amount end) as period_amount_source,
12+
sum(case when account_class = 'Asset' and account_type != 'Bank'
13+
then -converted_amount else converted_amount end) as period_converted_amount_source
1214
from {{ ref('quickbooks__balance_sheet') }}
1315
group by 1
1416
),
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{{ config(
2+
tags="fivetran_validations",
3+
enabled=var('fivetran_validation_tests_enabled', false) and var('using_journal_entry', True) and not var('cash_flow_statement_type_ordinal', [])
4+
) }}
5+
6+
-- Synthetic journal entries fund a bank account, purchase prepaid expenses and
7+
-- equipment, then release those assets. Asset purchases consume cash; releases
8+
-- generate cash. Bank, liability, and equity balances retain their usual signs.
9+
with expected as (
10+
11+
select *
12+
from {{ ref('cash_flow_signs_expected') }}
13+
),
14+
15+
actual as (
16+
17+
select *
18+
from {{ ref('quickbooks__cash_flow_statement') }}
19+
where account_id in ('96001', '96002', '96003', '96004', '96005')
20+
and cash_flow_period between cast('2024-01-01' as date) and cast('2024-03-01' as date)
21+
),
22+
23+
match_check as (
24+
25+
select
26+
expected.account_id as expected_account_id,
27+
actual.account_id as actual_account_id,
28+
expected.cash_flow_period,
29+
expected.cash_flow_type as expected_cash_flow_type,
30+
actual.cash_flow_type as actual_cash_flow_type,
31+
expected.cash_beginning_period as expected_beginning,
32+
actual.cash_beginning_period as actual_beginning,
33+
expected.cash_ending_period as expected_ending,
34+
actual.cash_ending_period as actual_ending,
35+
expected.cash_net_period as expected_net,
36+
actual.cash_net_period as actual_net,
37+
expected.cash_converted_beginning_period as expected_converted_beginning,
38+
actual.cash_converted_beginning_period as actual_converted_beginning,
39+
expected.cash_converted_ending_period as expected_converted_ending,
40+
actual.cash_converted_ending_period as actual_converted_ending,
41+
expected.cash_converted_net_period as expected_converted_net,
42+
actual.cash_converted_net_period as actual_converted_net
43+
from expected
44+
full outer join actual
45+
on cast(expected.account_id as {{ dbt.type_string() }}) = actual.account_id
46+
and cast(expected.cash_flow_period as date) = actual.cash_flow_period
47+
)
48+
49+
select *
50+
from match_check
51+
where expected_account_id is null
52+
or actual_account_id is null
53+
or actual_cash_flow_type is null
54+
or actual_cash_flow_type != expected_cash_flow_type
55+
or actual_beginning is null
56+
or actual_ending is null
57+
or actual_net is null
58+
or actual_converted_beginning is null
59+
or actual_converted_ending is null
60+
or actual_converted_net is null
61+
or abs(actual_beginning - expected_beginning) >= 0.01
62+
or abs(actual_ending - expected_ending) >= 0.01
63+
or abs(actual_net - expected_net) >= 0.01
64+
or abs(actual_converted_beginning - expected_converted_beginning) >= 0.01
65+
or abs(actual_converted_ending - expected_converted_ending) >= 0.01
66+
or abs(actual_converted_net - expected_converted_net) >= 0.01

‎models/docs.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ calculations are included to show if the payable/receivable has been fully paid
77

88
{% docs cash_flow_statement_table %}
99
Table that provides all line items necessary to construct a cash flow statement.
10+
Noncash Asset balances use the inverse of their balance-sheet signs so that increases reduce cash flow and decreases increase it. Bank, Liability, and Equity balances retain their balance-sheet signs.
1011
{% enddocs %}
1112

1213
{% docs expenses_sales_enhanced_table %}

0 commit comments

Comments
 (0)