From 151bb461825b0d878ab38a66ad69f8ea3a08a7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Roqu=C3=A9=20Paniagua?= Date: Sun, 19 Jan 2025 12:20:19 +0000 Subject: [PATCH] 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 --- .../xero/int_xero__sales_denom_mart.sql | 19 +++- models/intermediate/xero/schema.yml | 16 ++++ seeds/schema.yml | 87 +++++++++++++++++++ seeds/stg_seed__accounting_aggregations.csv | 35 ++++++++ 4 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 seeds/stg_seed__accounting_aggregations.csv diff --git a/models/intermediate/xero/int_xero__sales_denom_mart.sql b/models/intermediate/xero/int_xero__sales_denom_mart.sql index 2121938..5cea04b 100644 --- a/models/intermediate/xero/int_xero__sales_denom_mart.sql +++ b/models/intermediate/xero/int_xero__sales_denom_mart.sql @@ -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 diff --git a/models/intermediate/xero/schema.yml b/models/intermediate/xero/schema.yml index 5e0e38d..043ce75 100644 --- a/models/intermediate/xero/schema.yml +++ b/models/intermediate/xero/schema.yml @@ -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. diff --git a/seeds/schema.yml b/seeds/schema.yml index db9d86d..ed70844 100644 --- a/seeds/schema.yml +++ b/seeds/schema.yml @@ -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 diff --git a/seeds/stg_seed__accounting_aggregations.csv b/seeds/stg_seed__accounting_aggregations.csv new file mode 100644 index 0000000..35c3670 --- /dev/null +++ b/seeds/stg_seed__accounting_aggregations.csv @@ -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