removing duplicates from guesty and removing tests for edeposit_users

This commit is contained in:
Joaquin Ossa 2024-09-13 16:14:03 +02:00
parent ac1aed029d
commit 5551c97db0
4 changed files with 57 additions and 44 deletions

View file

@ -4,14 +4,23 @@
with
int_edeposit__verifications as (
select * from {{ ref("int_edeposit__verifications") }}
),
-- CTE to rank verifications by updated_at_utc per id_booking
ranked_verifications as (
select
v.*,
row_number() over (
partition by v.id_booking order by v.updated_at_utc desc
) as rn
from int_edeposit__verifications v
where v.version = 'V1' and v.id_booking is not null
)
select
v.id_verification,
v.id_booking,
v.verification_status,
v.is_cancelled,
-- when number_nights = 0 (booking's checkin and checkout are on the same day)
-- it's charged for just 1 night
-- Charge for 1 night if number_nights = 0
case
when v.number_nights = 0 and v.verification_status = '{{ ok_status }}'
then {{ cost_per_night }}
@ -21,5 +30,7 @@ select
end as ok_status_fee_in_gbp,
v.created_date_utc,
v.checkout_date_utc
from int_edeposit__verifications v
where v.version = 'V1' and v.id_booking is not null
from ranked_verifications v
where
-- Select only the most recent verification for each id_booking
v.rn = 1