Merged PR 2161: Sign for bank transactions

The bank transactions table coming from Xero has positive amounts for all transactions by default.

Nevertheless, some transactions are receiving and some are sending.

This PR implements sign for transactions amounts throughout the DWH so that aggregations work properly.

I've also left the transaction sign column in some spots since it might be useful for some aggregation wizardry (ie cancel out receiving transactions in resolutions so that counts are more accurate).

Related work items: #17551
This commit is contained in:
Pablo Martín 2024-07-01 12:02:25 +00:00
commit 915b9d5165
7 changed files with 115 additions and 42 deletions

View file

@ -833,7 +833,12 @@ models:
description: |
What kind of transaction is this record.
Can be one of: RECEIVE, RECEIVE-OVERPAYMENT, RECEIVE-PREPAYMENT, SPEND, SPEND-OVERPAYMENT, SPEND-PREPAYMENT, RECEIVE-TRANSFER, SPEND-TRANSFER
Can be one of: RECEIVE, RECEIVE-OVERPAYMENT, RECEIVE-PREPAYMENT,
SPEND, SPEND-OVERPAYMENT, SPEND-PREPAYMENT, RECEIVE-TRANSFER,
SPEND-TRANSFER
The type will affect the sign of all amounts. Amounts we send are
negative, amounts we receive are positive.
You can read more here: https://developer.xero.com/documentation/api/accounting/types#bank-transactions
tests:
@ -849,6 +854,19 @@ models:
- RECEIVE-TRANSFER
- SPEND-TRANSFER
- name: transaction_sign
data_type: numeric
description: |
The sign for the transactions. Spending transactions show as -1,
receiving transactions show as 1. This helps in converting the
transaction amounts in the right sign, since Xero brings all amounts
as positive by default.
tests:
- not_null
- accepted_values:
values:
- 1
- -1
- name: transaction_status
data_type: character varying

View file

@ -30,6 +30,7 @@ select
bt.id_bank_account,
bt.reference,
bt.transaction_type,
bt.transaction_sign,
bt.transaction_status,
bt.transaction_at_utc,
bt.transaction_date_utc,

View file

@ -10,6 +10,7 @@ select
bt.id_bank_account as id_bank_account,
bt.reference as reference,
bt.transaction_type as transaction_type,
bt.transaction_sign as transaction_sign,
bt.transaction_status as transaction_status,
bt.transaction_at_utc as transaction_at_utc,
bt.transaction_date_utc as transaction_date_utc,