data-dwh-dbt-project/models/intermediate/xero/schema.yml
Oriol Roqué Paniagua 68952223ca Merged PR 4228: First version of sales - monthly trends
# Description

New model that aggregates in a monthly basis the information from Xero sales. The aggregation is done by several categories, most of them to be included as filters in PBI. Metrics represent the amount without taxes in: 1) the current month, 2) the previous month, 3) twelve months ago, 4) current year YTD (fiscal year) and 5) previous year YTD (fiscal year).

It also propagates the model to reporting

# 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.
- [ ] I've picked the right materialization for the affected models. **I was hesitating between table or view. Table should speed up tests, but I intend to create a reporting table with a similar structure so probably a bit of waste of space. Anyway, not a big deal now**

# Other

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

Related work items: #26618
2025-01-31 08:33:15 +00:00

372 lines
11 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

version: 2
models:
- name: int_xero__invoices
columns:
- name: id_invoice
data_tests:
- not_null
- unique
- name: int_xero__credit_notes
columns:
- name: id_credit_note
data_tests:
- not_null
- unique
- name: int_xero__invoice_line_items
columns:
- name: id_line_item
data_tests:
- not_null
- unique
- name: int_xero__credit_note_line_items
columns:
- name: id_line_item
data_tests:
- not_null
- unique
- name: int_xero__bank_transactions
columns:
- name: id_bank_transaction
data_tests:
- not_null
- unique
- name: int_xero__sales_denom_mart
description: |
This table is a denormalized mix of all invoices and credit notes data.
It is built by creating a snowflake schema for the invoicing area and
another one for the crediting area. In both cases, the cardinality is
*:1 between line items and documents, and *:1 between documents and
contacts. Then, the invoice and credit note side get unioned to be stored
in a single structure. The only transformation that happens differently
across both is that credit note amounts get their sign reversed (* -1) so
that aggregations happen naturally (credit amounts subtract from invoice
amounts). The final granularity of the table is on the line item level.
Invoice and credit note records can be told apart through the
document_class field.
The word _document_ in the context of this table encompasses both invoices
and credit notes.
The source of amounts is identifiable by their prefix. `line_` amount
fields come from the line items data, while `header_` fields come from the
document level data. Aggregating line fields can be done without worries.
Document level data can't be summed or averaged since it's duplicated per
line item, so be careful with it.
Fields are not documented here: you can find more details in upstream
models.
columns:
- name: id_line_item
data_type: text
description: ""
data_tests:
- not_null
- unique
- name: id_item
data_type: text
description: ""
- name: document_class
data_type: text
description: |
Indicates whether the record belongs in an invoice or a credit note.
data_tests:
- not_null
- accepted_values:
values:
- "invoice"
- "credit note"
- name: id_account
data_type: text
description: ""
- name: account_code
data_type: text
description: ""
- name: account_name
data_type: text
description: ""
- name: item_code
data_type: text
description: ""
- name: quantity
data_type: numeric
description: ""
- name: unit_amount
data_type: numeric
description: ""
- name: line_amount_local_curr
data_type: numeric
description: ""
- name: line_amount_in_gbp
data_type: numeric
description: ""
- name: line_amount_wo_taxes_local_curr
data_type: numeric
description: ""
- name: line_amount_wo_taxes_in_gbp
data_type: numeric
description: ""
- name: tax_amount_local_curr
data_type: numeric
description: ""
- name: tax_amount_in_gbp
data_type: numeric
description: ""
- name: tax_type
data_type: text
description: ""
- name: document_currency_iso_4217
data_type: character varying
description: ""
data_tests:
- not_null
- length_between:
min_length: 3
max_length: 3
- name: line_description
data_type: text
description: ""
- name: id_document
data_type: character varying
description: ""
data_tests:
- not_null
- name: reference
data_type: character varying
description: ""
- name: document_number
data_type: character varying
description: ""
- name: document_issued_at_utc
data_type: timestamp with time zone
description: ""
- name: document_issued_date_utc
data_type: date
description: ""
- name: document_type
data_type: character varying
description: ""
data_tests:
- not_null
- accepted_values:
values:
- "ACCREC"
- "ACCPAY"
- "ACCRECCREDIT"
- "ACCPAYCREDIT"
- name: document_currency_iso_4217
data_type: character varying
description: ""
- name: exchange_rate_to_gbp
data_type: numeric
description: ""
data_tests:
- not_null
- not_negative
- name: document_status
data_type: character varying
description: ""
data_tests:
- not_null
- accepted_values:
values:
- PAID
- VOIDED
- DRAFT
- DELETED
- AUTHORISED
- SUBMITTED
- name: line_amount_tax_inclusiveness
data_type: character varying
description: ""
data_tests:
- accepted_values:
values:
- Inclusive
- Exclusive
- NoTax
- name: header_total_amount_local_curr
data_type: numeric
description: ""
- name: header_total_amount_in_gbp
data_type: numeric
description: ""
- name: header_total_amount_wo_tax_local_curr
data_type: numeric
description: ""
- name: header_total_amount_wo_tax_in_gbp
data_type: numeric
description: ""
- name: header_total_tax_local_curr
data_type: numeric
description: ""
- name: header_total_tax_in_gbp
data_type: numeric
description: ""
- name: header_total_due_local_curr
data_type: numeric
description: ""
- name: header_total_due_in_gbp
data_type: numeric
description: ""
- name: id_contact
data_type: character varying
description: ""
- name: id_deal
data_type: text
description: ""
- 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_l1_aggregation
data_type: character varying
description: |
The Level 1 aggregation for Financial reporting.
- name: accounting_financial_l2_aggregation
data_type: character varying
description: |
The Level 2 aggregation for Financial reporting.
- name: accounting_financial_l3_aggregation
data_type: character varying
description: |
The Level 3 aggregation for Financial reporting.
- name: int_xero__sales_monthly_trends
description: |
This model provides monthly aggregated sales and credit note data with
fiscal year alignment and period-over-period comparisons.
The model is built by aggregating the `int_xero__sales_denom_mart` model
at the monthly level, computing sales amounts without taxes in GBP, and
incorporating key financial aggregations.
Additionally, it calculates prior period trends:
- Previous month sales
- Previous year (same month) sales
- Year-to-date (YTD) sales for the current fiscal year
- YTD sales for the previous fiscal year
The fiscal year is determined based on an April-March cycle, where a
fiscal year is labeled by the year in which it ends (e.g., FY 2025
represents April 2024 March 2025).
columns:
- name: document_issued_month_utc
data_type: date
description: "The first day of the month when the document was issued, truncated to the month level."
data_tests:
- not_null
- name: fiscal_year
data_type: integer
description: |
"The fiscal year in which the document's issued month falls.
The fiscal year runs from April to March and is labeled by the year in which it ends
(e.g., FY 2025 represents April 2024 March 2025)."
- name: previous_fiscal_year
data_type: integer
description: "The fiscal year prior to the current one, based on the April-March cycle."
- name: document_status
data_type: text
description: "The status of the document (e.g., PAID, VOIDED, AUTHORISED, etc.)."
- name: document_type
data_type: text
description: "The type of document, indicating whether it is an invoice or credit note."
- name: id_deal
data_type: text
description: "The deal associated with the transaction, if applicable. Defaults to 'UNSET' if not provided."
- name: accounting_financial_l1_aggregation
data_type: text
description: "The Level 1 aggregation for Financial reporting."
- name: accounting_financial_l2_aggregation
data_type: text
description: "The Level 2 aggregation for Financial reporting."
- name: accounting_financial_l3_aggregation
data_type: text
description: "The Level 3 aggregation for Financial reporting."
- name: amount_wo_taxes_in_gbp
data_type: numeric
description: "Total sales amount without taxes, converted to GBP, aggregated at the monthly level."
- name: previous_month_amount_wo_taxes_in_gbp
data_type: numeric
description: "The sales amount without taxes (GBP) for the previous month within the same category."
- name: previous_year_amount_wo_taxes_in_gbp
data_type: numeric
description: "The sales amount without taxes (GBP) for the same month in the previous year within the same category."
- name: ytd_amount_wo_taxes_in_gbp
data_type: numeric
description: |
"Year-to-date (YTD) total of sales amount without taxes (GBP) from the start of the current fiscal
year up to the current month."
- name: previous_year_ytd_amount_wo_taxes_in_gbp
data_type: numeric
description: |
"Year-to-date (YTD) total of sales amount without taxes (GBP) from the start of the previous fiscal
year up to the same month."