# Description Hyperline invoices/credit notes have an issuing date that corresponds to the moment in which these are actually created. This is an issue since it means that an invoice or credit note posted today, 4th March 2025, that is supposed to be related to February 2025 invoicing cycle, will have: * If the document is posted in Hyperline, an issuing date on the March 2025 * If the document is NOT posted in Hyperline, an issuing date on February 2025 This PR just creates a field that handles the logic effectively, to be used further in other reports/kpis purposes. # 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. Related work items: #28158
415 lines
13 KiB
YAML
415 lines
13 KiB
YAML
version: 2
|
||
|
||
models:
|
||
- name: int_xero__invoices
|
||
columns:
|
||
- name: id_invoice
|
||
data_tests:
|
||
- not_null
|
||
- unique
|
||
- name: is_invoice_posted_in_hyperline
|
||
data_type: boolean
|
||
description: |
|
||
Indicates whether the invoice has been posted in Hyperline.
|
||
An invoice is considered posted in Hyperline if it has an
|
||
invoice type equal to ACCREC and follows the naming convention
|
||
20XX-Y, where 20XX is the posting year and Y is an autoincremental number.
|
||
data_tests:
|
||
- not_null
|
||
|
||
- name: int_xero__credit_notes
|
||
columns:
|
||
- name: id_credit_note
|
||
data_tests:
|
||
- not_null
|
||
- unique
|
||
- name: is_credit_note_posted_in_hyperline
|
||
data_type: boolean
|
||
description: |
|
||
Indicates whether the credit note has been posted in Hyperline.
|
||
A credit note is considered posted in Hyperline if it has a
|
||
credit note type equal to ACCRECCREDIT and follows the naming convention
|
||
CN-20XX-Y, where CN refers to Credit Note, 20XX is the posting year and
|
||
Y is an autoincremental number.
|
||
data_tests:
|
||
- not_null
|
||
|
||
- 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: is_document_posted_in_hyperline
|
||
data_type: boolean
|
||
description: |
|
||
Indicates whether the document has been posted in Hyperline.
|
||
A document is considered posted in Hyperline if it follows this logic:
|
||
- For invoices, if the invoice type equals to ACCREC and the document number
|
||
follows the naming convention 20XX-Y, where 20XX is the posting year and Y is
|
||
an autoincremental number.
|
||
- For credit notes, if the credit note type equal to ACCRECCREDIT and the
|
||
document number follows the naming convention CN-20XX-Y, where CN refers to
|
||
Credit Note, 20XX is the posting year and Y is an autoincremental number.
|
||
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_is_effective_at_end_of_month_utc
|
||
data_type: date
|
||
description: |
|
||
The last day of the month when the document is effective.
|
||
This is used to align the document with the correct invoicing cycle period.
|
||
For documents posted in Hyperline, this represents the last day of the previous
|
||
month to the issuing date. For documents not posted in Hyperline, this is the
|
||
last day of the month when the document was issued.
|
||
- 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."
|