Skip to content
Merged
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# dbt_xero v1.6.0

[PR #82](https://github.com/fivetran/dbt_xero/pull/82) includes the following update:

## Schema/Data Change
**1 total change • 1 possible breaking change**

| Data Model(s) | Change type | Old | New | Notes |
| ------------- | ----------- | --- | --- | ----- |
| [`xero__balance_sheet_report`](https://fivetran.github.io/dbt_xero/#!/model/model.xero.xero__balance_sheet_report) (possible breaking change) | Data Change | `Retained Earnings` vs. `Current Year Earnings` split anchored to the runtime `current_date`. | Split anchored to each report month's (`date_month`) fiscal year. | Historical months now reconcile with the native Xero balance sheet and are stable across runs. |

# dbt_xero v1.6.0-a1

[PR #80](https://github.com/fivetran/dbt_xero/pull/80) is a pre-release that includes the following update:

## Schema/Data Change
**1 total change • 1 possible breaking change**

| Data Model(s) | Change type | Old | New | Notes |
| ------------- | ----------- | --- | --- | ----- |
| [`xero__balance_sheet_report`](https://fivetran.github.io/dbt_xero/#!/model/model.xero.xero__balance_sheet_report) (possible breaking change) | Data Change | `Retained Earnings` vs. `Current Year Earnings` split anchored to the runtime `current_date`. | Split anchored to each report month's (`date_month`) fiscal year. | Historical months now reconcile with the native Xero balance sheet and are stable across runs. |

# dbt_xero v1.5.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Include the following xero package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/xero
version: [">=1.5.0", "<1.6.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=1.6.0", "<1.7.0"] # we recommend using ranges to capture non-breaking changes automatically
```
> All required sources and staging models are now bundled into this transformation package. Do not include `fivetran/xero_source` in your `packages.yml` since this package has been deprecated.

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'xero'
version: '1.5.0'
version: '1.6.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<3.0.0"]

Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'xero_integration_tests'
version: '1.5.0'
version: '1.6.0'
profile: 'integration_tests'
config-version: 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
enabled=var('fivetran_validation_tests_enabled', false)
) }}

-- account_name is included in the grain because the `Retained Earnings` and `Current Year Earnings`
-- roll-up rows both have a null account_id; keying on account_id alone collapses them into one key
-- and produces a many-to-many diff.

with prod as (

select
select
date_month,
account_name,
case when account_id is null then '' else account_id end as account_id,
source_relation,
net_amount
Expand All @@ -15,8 +20,9 @@ with prod as (

dev as (

select
select
date_month,
account_name,
case when account_id is null then '' else account_id end as account_id,
source_relation,
net_amount
Expand All @@ -26,13 +32,15 @@ dev as (
diffed as (
select
coalesce(prod.date_month, dev.date_month) as date_month,
coalesce(prod.account_name, dev.account_name) as account_name,
coalesce(prod.account_id, dev.account_id) as account_id,
coalesce(prod.source_relation, dev.source_relation) as source_relation,
prod.net_amount as prod_net_amount,
dev.net_amount as dev_net_amount
from prod
full outer join dev
on prod.date_month = dev.date_month
and prod.account_name = dev.account_name
and prod.account_id = dev.account_id
and prod.source_relation = dev.source_relation
),
Expand All @@ -44,4 +52,4 @@ final as (
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ with calendar as (
journal_line.account_id,
journal.source_relation,

{% if using_tracking %}
{% if using_tracking and tracking_cols %}
{{ dbt_utils.star(
from=ref('int_xero__journal_line_pivoted_tracking_categories'),
relation_alias='pivoted_tracking_categories',
Expand Down
50 changes: 31 additions & 19 deletions models/xero__balance_sheet_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,47 @@ with calendar as (

), organization as (

select
*,
cast(extract(year from current_date) as {{ dbt.type_string() }}) as current_year,
cast(extract(year from {{ dbt.dateadd('year', 1, 'current_date') }}) as {{ dbt.type_string() }}) as next_year
select *
from {{ ref('stg_xero__organization') }}

), calendar_organization as (

-- Derive the fiscal year from each report month (date_month) rather than from current_date,
-- so that each month's balance sheet is classified against its own fiscal year boundary.
select
calendar.date_month,
organization.source_relation,
organization.financial_year_end_month,
organization.financial_year_end_day,
cast(extract(year from calendar.date_month) as {{ dbt.type_string() }}) as date_month_year,
cast(extract(year from {{ dbt.dateadd('year', 1, 'calendar.date_month') }}) as {{ dbt.type_string() }}) as date_month_next_year
from calendar
cross join organization

), year_end as (

-- Calculate the current financial year-end date for each organization:
-- Calculate the financial year-end date that applies to each report month (date_month):
-- For February, determine last day by subtracting 1 day from March 1, avoiding leap year logic.
-- Compare the year end date to the current date:
-- Use this year's date if it's on or after the current date.
-- Compare the year end date to the report month:
-- Use this year's date if it's on or after the report month.
-- Otherwise, use the next year's corresponding date.
select
select
date_month,
source_relation,
case when financial_year_end_month = 2 and financial_year_end_day = 29
then
case when cast({{ dbt.dateadd('day', -1, "cast(current_year || '-03-01' as date)") }} as date) >= current_date
then cast({{ dbt.dateadd('day', -1, "cast(current_year || '-03-01' as date)") }} as date)
else cast({{ dbt.dateadd('day', -1, "cast(next_year || '-03-01' as date)") }} as date)
case when cast({{ dbt.dateadd('day', -1, "cast(date_month_year || '-03-01' as date)") }} as date) >= date_month
then cast({{ dbt.dateadd('day', -1, "cast(date_month_year || '-03-01' as date)") }} as date)
else cast({{ dbt.dateadd('day', -1, "cast(date_month_next_year || '-03-01' as date)") }} as date)
end
else
case when cast(current_year || '-' || financial_year_end_month || '-' || financial_year_end_day as date) >= current_date
then cast(current_year || '-' || financial_year_end_month || '-' || financial_year_end_day as date)
else cast(next_year || '-' || financial_year_end_month || '-' || financial_year_end_day as date)
case when cast(date_month_year || '-' || financial_year_end_month || '-' || financial_year_end_day as date) >= date_month
then cast(date_month_year || '-' || financial_year_end_month || '-' || financial_year_end_day as date)
else cast(date_month_next_year || '-' || financial_year_end_month || '-' || financial_year_end_day as date)
end
end as current_year_end_date

from organization
from calendar_organization

), joined as (

Expand All @@ -66,16 +77,17 @@ with calendar as (
when ledger.account_class in ('ASSET','EQUITY','LIABILITY') then ledger.account_class
else 'EQUITY'
end as account_class,
ledger.source_relation,
ledger.source_relation,
sum(ledger.net_amount) as net_amount
from calendar
inner join ledger
on calendar.date_month >= cast({{ dbt.date_trunc('month', 'ledger.journal_date') }} as date)
cross join year_end
where year_end.source_relation = ledger.source_relation
inner join year_end
on year_end.date_month = calendar.date_month
and year_end.source_relation = ledger.source_relation
{{ dbt_utils.group_by(7) }}

)

select *
from joined
from joined