Merged PR 4107: First version of accounting aggregations

# Description

Creates a seed to define how to aggregate the different revenue/cost sources, at account code level.

This is propagated to the sales denom mart in intermediate.

This is not complete, but should be a good starting point and it enables moving forward with a couple of tickets regarding KPIs revenue refactor and further Finance reporting, by just keeping a single source of truth. It's mostly focusing on the Don't Repeat Yourself

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

First version of accounting aggregations - not complete

Related work items: #26618
This commit is contained in:
Oriol Roqué Paniagua 2025-01-19 12:20:19 +00:00
parent 06bdb81cfe
commit 151bb46182
4 changed files with 154 additions and 3 deletions

View file

@ -7,7 +7,10 @@ with
select * from {{ ref("int_xero__credit_note_line_items") }}
),
int_xero__credit_notes as (select * from {{ ref("int_xero__credit_notes") }}),
int_xero__contacts as (select * from {{ ref("int_xero__contacts") }})
int_xero__contacts as (select * from {{ ref("int_xero__contacts") }}),
stg_seed__accounting_aggregations as (
select * from {{ ref("stg_seed__accounting_aggregations") }}
)
select
ili.id_line_item as id_line_item,
ili.id_item as id_item,
@ -48,11 +51,16 @@ select
c.id_contact as id_contact,
c.id_deal as id_deal,
c.contact_name as contact_name
c.contact_name as contact_name,
aa.root_aggregation as accounting_root_aggregation,
aa.kpis_aggregation as accounting_kpis_aggregation,
aa.financial_aggregation as accounting_financial_aggregation
from int_xero__invoice_line_items ili
left join int_xero__invoices i on i.id_invoice = ili.id_invoice
left join int_xero__contacts c on c.id_contact = i.id_contact
left join stg_seed__accounting_aggregations aa on aa.account_code = ili.account_code
union all
@ -99,8 +107,13 @@ select
c.id_contact,
c.id_deal,
c.contact_name
c.contact_name,
aa.root_aggregation,
aa.kpis_aggregation,
aa.financial_aggregation
from int_xero__credit_note_line_items cnli
left join int_xero__credit_notes cn on cn.id_credit_note = cnli.id_credit_note
left join int_xero__contacts c on c.id_contact = cn.id_contact
left join stg_seed__accounting_aggregations aa on aa.account_code = cnli.account_code

View file

@ -259,3 +259,19 @@ models:
- name: contact_name
data_type: character varying
description: ""
- name: accounting_root_aggregation
data_type: character varying
description: |
The root aggregation per account code. This is the main
aggregation that is used to retrieve low-level data.
- name: accounting_kpis_aggregation
data_type: character varying
description: |
The default macro-aggregation for Invoiced KPIs.
- name: accounting_financial_aggregation
data_type: character varying
description: |
The default macro-aggregation for Financial reporting.