Fixed model, added created_date and checkout_date

This commit is contained in:
Joaquin Ossa 2024-09-03 17:05:13 +02:00
parent c24c875336
commit 7d8983e0dd
2 changed files with 48 additions and 24 deletions

View file

@ -8,8 +8,8 @@ with
select * from {{ ref("int_edeposit__verifications") }} select * from {{ ref("int_edeposit__verifications") }}
), ),
stg_core__edeposit_user as (select * from {{ ref("stg_core__edeposit_user") }}), stg_core__edeposit_user as (select * from {{ ref("stg_core__edeposit_user") }}),
stg_xedotcom__exchange_rates as ( int_daily_currency_exchange_rates as (
select * from {{ ref("stg_xedotcom__exchange_rates") }} select * from {{ ref("int_daily_currency_exchange_rates") }}
), ),
edeposit_records as ( edeposit_records as (
select select
@ -17,9 +17,8 @@ with
v.id_user_partner, v.id_user_partner,
v.id_booking, v.id_booking,
eu.currency, eu.currency,
er.rate, cer.rate,
v.is_cancelled, v.is_cancelled,
v.creation_at_utc,
case case
when v.verification_status in {{ ok_status }} when v.verification_status in {{ ok_status }}
then v.nightly_fee_local * v.number_nights then v.nightly_fee_local * v.number_nights
@ -27,7 +26,7 @@ with
end as ok_status_fee_in_txn_currency, end as ok_status_fee_in_txn_currency,
case case
when v.verification_status in {{ ok_status }} when v.verification_status in {{ ok_status }}
then er.rate * v.nightly_fee_local * v.number_nights then cer.rate * v.nightly_fee_local * v.number_nights
else 0 else 0
end as ok_status_fee_in_gbp, end as ok_status_fee_in_gbp,
case case
@ -37,17 +36,17 @@ with
end as rejected_fee_in_txn_currency, end as rejected_fee_in_txn_currency,
case case
when v.verification_status = '{{ rejected_status }}' when v.verification_status = '{{ rejected_status }}'
then er.rate * {{ rejected_fee }} then cer.rate * {{ rejected_fee }}
else 0 else 0
end as rejected_fee_in_gbp, end as rejected_fee_in_gbp,
to_char(v.checkout_at_utc, 'YYYY-MM') as year_month_checkout to_char(v.checkout_at_utc, 'YYYY-MM') as year_month_checkout
from int_edeposit__verifications v from int_edeposit__verifications v
inner join stg_core__edeposit_user eu on v.id_user_partner = eu.id_user_partner inner join stg_core__edeposit_user eu on v.id_user_partner = eu.id_user_partner
inner join left join
stg_xedotcom__exchange_rates er int_daily_currency_exchange_rates cer
on er.from_currency = eu.currency on cer.from_currency = eu.currency
and er.rate_date_utc = v.checkout_date_utc and cer.rate_date_utc = v.checkout_date_utc
and er.to_currency = 'GBP' and cer.to_currency = 'GBP'
where version = 'V2' where version = 'V2'
), ),
monthly_cancellation_threshold as ( monthly_cancellation_threshold as (
@ -65,12 +64,13 @@ with
group by id_user_partner, year_month_checkout group by id_user_partner, year_month_checkout
) )
select select
id_verification, v.id_verification,
currency, v.id_booking,
ok_status_fee_in_txn_currency, er.currency,
ok_status_fee_in_gbp, er.ok_status_fee_in_txn_currency,
rejected_fee_in_txn_currency, er.ok_status_fee_in_gbp,
rejected_fee_in_gbp, er.rejected_fee_in_txn_currency,
er.rejected_fee_in_gbp,
case case
when ct.is_cancellation_threshold_surpassed is true when ct.is_cancellation_threshold_surpassed is true
then {{ cancellation_fee }} then {{ cancellation_fee }}
@ -80,9 +80,12 @@ select
when ct.is_cancellation_threshold_surpassed is true when ct.is_cancellation_threshold_surpassed is true
then rate * {{ cancellation_fee }} then rate * {{ cancellation_fee }}
else 0 else 0
end as cancelled_fee_in_gbp end as cancelled_fee_in_gbp,
from edeposit_records er v.created_date_utc,
left join v.checkout_date_utc
from int_edeposit__verifications v
inner join edeposit_records er on er.id_verification = v.id_verification
inner join
monthly_cancellation_threshold ct monthly_cancellation_threshold ct
on ( on (
er.id_user_partner = ct.id_user_partner er.id_user_partner = ct.id_user_partner

View file

@ -21,7 +21,10 @@ models:
- name: id_booking - name: id_booking
data_type: text data_type: text
description: "unique Superhog generated id for a booking" description:
"unique Superhog generated id for a booking.
note that this could be duplicated and both will be charged,
it's up to the user to no generate duplicate verifications"
- name: id_user_partner - name: id_user_partner
data_type: text data_type: text
@ -207,9 +210,6 @@ models:
data_type: date data_type: date
description: "Date of creation of the verification in the system" description: "Date of creation of the verification in the system"
- name: created_date_utc
data_type: date
description: "Date of creation of the verification in the system"
- name: int_edeposit__verification_fees - name: int_edeposit__verification_fees
description: description:
"This table shows all fee charges per verification for E-deposit. "This table shows all fee charges per verification for E-deposit.
@ -225,6 +225,15 @@ models:
- unique - unique
- not_null - not_null
- name: id_booking
data_type: text
description:
"unique Superhog generated id for a booking.
note that this could be duplicated and both will be charged,
it's up to the user to no generate duplicate verifications"
tests:
- not_null
- name: currency - name: currency
data_type: text data_type: text
description: "currency in which the transaction actually happened" description: "currency in which the transaction actually happened"
@ -284,3 +293,15 @@ models:
- dbt_expectations.expect_column_values_to_be_between: - dbt_expectations.expect_column_values_to_be_between:
min_value: 0 min_value: 0
strictly: false strictly: false
- name: checkout_date_utc
data_type: date
description: "Date of checkout for the booking"
tests:
- not_null
- name: created_date_utc
data_type: date
description: "Date of creation of the verification in the system"
tests:
- not_null