modified model

This commit is contained in:
Joaquin Ossa 2024-08-30 11:33:55 +02:00
parent 4cfc0dcd45
commit 906bccce0e
2 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,60 @@
{% set ok_status = ("Approved", "Flagged") %}
{% set rejected_status = "Rejected" %}
{% set rejected_fee = 0.25 %}
{% set cancellation_fee = 0.25 %}
{% set cancellation_threshold = 0.05 %}
with
int_edeposit__verifications as (
select * from {{ ref("int_edeposit__verifications") }}
),
edeposit_records as (
select
id_verification,
id_user_partner,
id_booking,
is_cancelled,
creation_at_utc,
case
when verification_status in {{ ok_status }}
then nightly_fee_local * number_nights
else 0
end as ok_status_fee,
case
when verification_status = '{{ rejected_status }}'
then {{ rejected_fee }}
else 0
end as rejected_fee,
to_char(checkout_at_utc, 'YYYY-MM') as year_month_checkout
from int_edeposit__verifications
where version = 'V2'
),
monthly_cancellation_threshold as (
select
id_user_partner,
year_month_checkout,
case
when
sum(cast(is_cancelled as integer))::decimal / count(id_booking)
>= {{ cancellation_threshold }}
then true
else false
end as is_cancellation_threshold_surpassed
from edeposit_records
group by id_user_partner, year_month_checkout
)
select
id_verification,
ok_status_fee,
rejected_fee,
case
when ct.is_cancellation_threshold_surpassed is true
then {{ cancellation_fee }}
else 0
end as cancelled_fee
from edeposit_records er
left join
monthly_cancellation_threshold ct
on (
er.id_user_partner = ct.id_user_partner
and er.year_month_checkout = ct.year_month_checkout
)