New xero model for resolutions payments

This commit is contained in:
Joaquin 2025-04-17 16:39:32 +02:00
parent 2352716dae
commit 623d30bf80
2 changed files with 165 additions and 0 deletions

View file

@ -0,0 +1,70 @@
{% set resolutions_host_payment_account_name = "('RESOLUTIONS - HOST PAYMENT')" %}
{% set relevant_transaction_status = "('AUTHORISED')" %}
{% set resolutions_credited_account_code = "('316')" %}
{% set resolutions_credited_documents = "('ACCRECCREDIT')" %}
{{
config(
materialized="table",
unique_key=["id_account", "account_code", "account_name", "line_description"],
)
}}
with
int_xero__sales_denom_mart as (
select * from {{ ref("int_xero__sales_denom_mart") }}
),
int_xero__bank_transactions as (
select * from {{ ref("int_xero__bank_transactions") }}
),
int_xero__bank_transaction_line_items as (
select * from {{ ref("int_xero__bank_transaction_line_items") }}
),
int_xero__contacts as (select * from {{ ref("int_xero__contacts") }})
select
blt.id_account,
blt.account_code,
blt.account_name,
blt.line_description,
'BANK_TRANSACTION' as document_type,
bt.transaction_date_utc,
xc.id_deal,
blt.quantity,
blt.unit_amount,
blt.line_amount_local_curr,
blt.line_amount_in_gbp,
blt.line_amount_wo_taxes_local_curr,
blt.line_amount_wo_taxes_in_gbp,
blt.tax_amount_local_curr,
blt.tax_amount_in_gbp,
blt.transaction_currency_iso_4217
from int_xero__bank_transactions bt
inner join
int_xero__bank_transaction_line_items blt
on bt.id_bank_transaction = blt.id_bank_transaction
and upper(blt.account_name) in {{ resolutions_host_payment_account_name }}
and upper(bt.transaction_status) in {{ relevant_transaction_status }}
left join int_xero__contacts xc on xc.id_contact = bt.id_contact
union all
select
sdm.id_account,
sdm.account_code,
sdm.account_name,
sdm.line_description,
sdm.document_type,
sdm.document_is_effective_at_end_of_month_utc,
xc.id_deal,
sdm.quantity,
sdm.unit_amount,
sdm.line_amount_local_curr,
sdm.line_amount_in_gbp,
sdm.line_amount_wo_taxes_local_curr,
sdm.line_amount_wo_taxes_in_gbp,
sdm.tax_amount_local_curr,
sdm.tax_amount_in_gbp,
sdm.document_currency_iso_4217
from int_xero__sales_denom_mart sdm
left join int_xero__contacts xc on xc.id_contact = sdm.id_contact
where
sdm.account_name in {{ resolutions_credited_account_code }}
and sdm.document_type in {{ resolutions_credited_documents }}

View file

@ -453,3 +453,98 @@ models:
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."
- name: int_xero__resolutions_transactions
description: |
This model provides a view of transactions related to resolutions, including details
such as transaction date, associated account, and transaction amount.
Previously, all resolution-related transaction data was stored in the `int_xerp__bank_transactions`
model. However, some resolution transactions have been, and will continue to be, credited through
the standard invoicing process — these are stored in the `int_xerp__sales_denom_mart` model.
This model is built by joining the `int_xerp__bank_transactions` and `int_xerp__sales_denom_mart`
models to provide a unified view of resolution transactions.
columns:
- name: id_account
data_type: text
description: "Unique identifier of the account associated with the transaction."
data_tests:
- not_null
- name: account_code
data_type: text
description: "The code of the account associated with the transaction."
data_tests:
- not_null
- name: account_name
data_type: text
description: "The name of the account associated with the transaction."
data_tests:
- not_null
- name: line_description
data_type: text
description: "Description of the transaction line item."
- name: document_type
data_type: text
description: "The type of document associated with the transaction."
data_tests:
- not_null
- accepted_values:
values:
- "ACCREC"
- "ACCPAY"
- "ACCRECCREDIT"
- "ACCPAYCREDIT"
- "BANK_TRANSACTION"
- name: transaction_date_utc
data_type: date
description: "The date of the transaction in UTC."
- name: id_deal
data_type: text
description: |
"Unique identifier of an account associated with the transaction."
- name: quantity
data_type: numeric
description: "The quantity of transactions."
- name: unit_amount
data_type: numeric
description: "The unit amount of the transaction."
- name: line_amount_local_curr
data_type: numeric
description: "The transaction amount in the local currency."
- name: line_amount_in_gbp
data_type: numeric
description: "The transaction amount in GBP."
- name: line_amount_wo_taxes_local_curr
data_type: numeric
description: "The transaction amount without taxes in the local currency."
- name: line_amount_wo_taxes_in_gbp
data_type: numeric
description: "The transaction amount without taxes in GBP."
- name: tax_amount_local_curr
data_type: numeric
description: "The tax amount in the local currency."
- name: tax_amount_in_gbp
data_type: numeric
description: "The tax amount in GBP."
- name: transaction_currency_iso_4217
data_type: character varying
description: "The currency of the transaction, represented in ISO 4217 format."