diff --git a/models/reporting/xero/schema.yaml b/models/reporting/xero/schema.yaml index 876c65c..a452a2b 100644 --- a/models/reporting/xero/schema.yaml +++ b/models/reporting/xero/schema.yaml @@ -1124,3 +1124,219 @@ models: tests: - not_null - unique + + - name: 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. + + Most fields are not documented here: you can find more details in upstream + models. + + columns: + - name: id_line_item + data_type: text + description: "" + 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. + tests: + - not_null + - accepted_values: + values: + - 'invoice' + - 'credit note' + + - 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: "" + 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: "" + 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: "" + 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: "" + tests: + - not_null + - not_negative + + - name: document_status + data_type: character varying + description: "" + tests: + - not_null + - accepted_values: + values: + - PAID + - VOIDED + - DRAFT + - DELETED + - AUTHORISED + - SUBMITTED + + - name: line_amount_tax_inclusiveness + data_type: character varying + description: "" + 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: "" diff --git a/models/reporting/xero/xero__sales_denom_mart.sql b/models/reporting/xero/xero__sales_denom_mart.sql new file mode 100644 index 0000000..c045474 --- /dev/null +++ b/models/reporting/xero/xero__sales_denom_mart.sql @@ -0,0 +1,42 @@ +with + int_xero__sales_denom_mart as ( + select * from {{ ref("int_xero__sales_denom_mart") }} + ) +select + sdm.id_line_item as id_line_item, + sdm.id_item as id_item, + sdm.document_class as document_class, + sdm.item_code as item_code, + sdm.quantity as quantity, + sdm.unit_amount as unit_amount, + sdm.line_amount_local_curr as line_amount_local_curr, + sdm.line_amount_in_gbp as line_amount_in_gbp, + sdm.line_amount_wo_taxes_local_curr as line_amount_wo_taxes_local_curr, + sdm.line_amount_wo_taxes_in_gbp as line_amount_wo_taxes_in_gbp, + sdm.tax_amount_local_curr as tax_amount_local_curr, + sdm.tax_amount_in_gbp as tax_amount_in_gbp, + sdm.tax_type as tax_type, + sdm.line_description as line_description, + sdm.id_document as id_document, + sdm.reference as reference, + sdm.document_number as document_number, + sdm.document_issued_at_utc as document_issued_at_utc, + sdm.document_issued_date_utc as document_issued_date_utc, + sdm.document_type as document_type, + sdm.document_currency_iso_4217 as document_currency_iso_4217, + sdm.exchange_rate_to_gbp as exchange_rate_to_gbp, + sdm.document_status as document_status, + sdm.line_amount_tax_inclusiveness as line_amount_tax_inclusiveness, + sdm.header_total_amount_local_curr as header_total_amount_local_curr, + sdm.header_total_amount_in_gbp as header_total_amount_in_gbp, + sdm.header_total_amount_wo_tax_local_curr as header_total_amount_wo_tax_local_curr, + sdm.header_total_amount_wo_tax_in_gbp as header_total_amount_wo_tax_in_gbp, + sdm.header_total_tax_local_curr as header_total_tax_local_curr, + sdm.header_total_tax_in_gbp as header_total_tax_in_gbp, + sdm.header_total_due_local_curr as header_total_due_local_curr, + sdm.header_total_due_in_gbp as header_total_due_in_gbp, + sdm.id_contact as id_contact, + sdm.id_deal as id_deal, + sdm.contact_name as contact_name + +from int_xero__sales_denom_mart sdm