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.

View file

@ -174,3 +174,90 @@ seeds:
data_type: numeric
description: |
How much we charge per night in this time range.
- name: stg_seed__accounting_aggregations
description: |
Account codes and their respective aggregations.
config:
column_types:
account_code: varchar(3)
columns:
- name: account_code
data_type: character varying
description: |
The account code for this aggregation. This is the code that is used
in the accounting system.
data_tests:
- not_null
- unique
- dbt_expectations.expect_column_values_to_match_regex:
regex: "^[0-9]{3}$"
- name: root_aggregation
data_type: character varying
description: |
The root aggregation for this account code. This is the main
aggregation that is used to retrieve low-level data.
data_tests:
- not_null
- accepted_values:
values:
- Other Invoiced Revenue
- Verification Fees
- Listing Fees
- Booking Fees
- Athena API
- E-Deposit API
- Guesty Resolutions
- Basic Protection
- Waiver Pro
- Id Verification
- Protection Plus
- Screening Plus
- Sex Offenders Check
- Protection Pro
- Basic Screening
- Damage Host-Waiver Payments
- Damage Waiver Fees
- Deposit Fees
- Check In Cover
- Resolution Process for Protection Services
- Resolution Process for Deposit Management Services
- Basic Waiver
- Waiver Plus
- Basic Damage Deposit
- name: kpis_aggregation
data_type: character varying
description: |
The default macro-aggregation for Invoiced KPIs.
data_tests:
- not_null
- accepted_values:
values:
- Unknown
- Invoiced Operator Revenue
- Invoiced API Revenue
- Damage Host-Waiver Payments
- Accounting Resolutions
- Accounting Guest Revenue
- name: financial_aggregation
data_type: character varying
description: |
The default macro-aggregation for Financial reporting.
data_tests:
- not_null
- accepted_values:
values:
- Unknown
- Guest Screening and Protection
- Mediation and Resolution
- Damage Host-Waiver Payments
- Guest Products
- Deposit Management

View file

@ -0,0 +1,35 @@
account_code,root_aggregation,kpis_aggregation,financial_aggregation
"200",Other Invoiced Revenue,Unknown,Guest Screening and Protection
"201",Damage Waiver Fees,Accounting Guest Revenue,Deposit Management
"202",Deposit Fees,Accounting Guest Revenue,Deposit Management
"203",Verification Fees,Invoiced Operator Revenue,Guest Screening and Protection
"204",Listing Fees,Invoiced Operator Revenue,Guest Screening and Protection
"206",Booking Fees,Invoiced Operator Revenue,Guest Screening and Protection
"207",Listing Fees,Invoiced Operator Revenue,Guest Screening and Protection
"208",Booking Fees,Invoiced Operator Revenue,Guest Screening and Protection
"209",Listing Fees,Invoiced Operator Revenue,Guest Screening and Protection
"210",Booking Fees,Invoiced Operator Revenue,Guest Screening and Protection
"211",Listing Fees,Invoiced Operator Revenue,Guest Screening and Protection
"212",Booking Fees,Invoiced Operator Revenue,Guest Screening and Protection
"213",Listing Fees,Invoiced Operator Revenue,Guest Screening and Protection
"214",Booking Fees,Invoiced Operator Revenue,Guest Screening and Protection
"215",Listing Fees,Invoiced Operator Revenue,Guest Screening and Protection
"216",Booking Fees,Invoiced Operator Revenue,Guest Screening and Protection
"219",Athena API,Invoiced API Revenue,Guest Screening and Protection
"220",E-Deposit API,Invoiced API Revenue,Guest Screening and Protection
"221",Guesty Resolutions,Accounting Resolutions,Mediation and Resolution
"222",Check In Cover,Accounting Guest Revenue,Guest Products
"227",Basic Protection,Invoiced Operator Revenue,Guest Screening and Protection
"228",Waiver Pro,Invoiced Operator Revenue,Deposit Management
"229",Id Verification,Invoiced Operator Revenue,Guest Screening and Protection
"230",Protection Plus,Invoiced Operator Revenue,Guest Screening and Protection
"231",Screening Plus,Invoiced Operator Revenue,Guest Screening and Protection
"232",Sex Offenders Check,Invoiced Operator Revenue,Guest Screening and Protection
"233",Protection Pro,Invoiced Operator Revenue,Guest Screening and Protection
"234",Basic Screening,Invoiced Operator Revenue,Guest Screening and Protection
"235",Resolution Process for Protection Services,Accounting Resolutions,Guest Screening and Protection
"236",Basic Waiver,Accounting Guest Revenue,Deposit Management
"237",Waiver Plus,Accounting Guest Revenue,Deposit Management
"238",Basic Damage Deposit,Accounting Guest Revenue,Deposit Management
"239",Resolution Process for Deposit Management Services,Accounting Resolutions,Deposit Management
"301",Damage Host-Waiver Payments,Damage Host-Waiver Payments,Damage Host-Waiver Payments
1 account_code root_aggregation kpis_aggregation financial_aggregation
2 200 Other Invoiced Revenue Unknown Guest Screening and Protection
3 201 Damage Waiver Fees Accounting Guest Revenue Deposit Management
4 202 Deposit Fees Accounting Guest Revenue Deposit Management
5 203 Verification Fees Invoiced Operator Revenue Guest Screening and Protection
6 204 Listing Fees Invoiced Operator Revenue Guest Screening and Protection
7 206 Booking Fees Invoiced Operator Revenue Guest Screening and Protection
8 207 Listing Fees Invoiced Operator Revenue Guest Screening and Protection
9 208 Booking Fees Invoiced Operator Revenue Guest Screening and Protection
10 209 Listing Fees Invoiced Operator Revenue Guest Screening and Protection
11 210 Booking Fees Invoiced Operator Revenue Guest Screening and Protection
12 211 Listing Fees Invoiced Operator Revenue Guest Screening and Protection
13 212 Booking Fees Invoiced Operator Revenue Guest Screening and Protection
14 213 Listing Fees Invoiced Operator Revenue Guest Screening and Protection
15 214 Booking Fees Invoiced Operator Revenue Guest Screening and Protection
16 215 Listing Fees Invoiced Operator Revenue Guest Screening and Protection
17 216 Booking Fees Invoiced Operator Revenue Guest Screening and Protection
18 219 Athena API Invoiced API Revenue Guest Screening and Protection
19 220 E-Deposit API Invoiced API Revenue Guest Screening and Protection
20 221 Guesty Resolutions Accounting Resolutions Mediation and Resolution
21 222 Check In Cover Accounting Guest Revenue Guest Products
22 227 Basic Protection Invoiced Operator Revenue Guest Screening and Protection
23 228 Waiver Pro Invoiced Operator Revenue Deposit Management
24 229 Id Verification Invoiced Operator Revenue Guest Screening and Protection
25 230 Protection Plus Invoiced Operator Revenue Guest Screening and Protection
26 231 Screening Plus Invoiced Operator Revenue Guest Screening and Protection
27 232 Sex Offenders Check Invoiced Operator Revenue Guest Screening and Protection
28 233 Protection Pro Invoiced Operator Revenue Guest Screening and Protection
29 234 Basic Screening Invoiced Operator Revenue Guest Screening and Protection
30 235 Resolution Process for Protection Services Accounting Resolutions Guest Screening and Protection
31 236 Basic Waiver Accounting Guest Revenue Deposit Management
32 237 Waiver Plus Accounting Guest Revenue Deposit Management
33 238 Basic Damage Deposit Accounting Guest Revenue Deposit Management
34 239 Resolution Process for Deposit Management Services Accounting Resolutions Deposit Management
35 301 Damage Host-Waiver Payments Damage Host-Waiver Payments Damage Host-Waiver Payments