change logic in new CTE to use new tables

This commit is contained in:
Pablo Martin 2025-05-30 15:47:35 +02:00
parent 58c1ae5b8f
commit 7339cf4c87

View file

@ -2,9 +2,16 @@ with
int_core__verification_requests as (
select * from {{ ref("int_core__verification_requests") }}
),
stg_core__currency as (select * from {{ ref("stg_core__currency") }}),
stg_core__verification_set_to_verification_type as (
select * from {{ ref("stg_core__verification_set_to_verification_type") }}
),
stg_core__verification_request_to_guest_product as (
select * from {{ ref("stg_core__verification_request_to_guest_product") }}
),
stg_core__guest_product_configuration_price_plan as (
select * from {{ ref("stg_core__guest_product_configuration_price_plan") }}
),
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
int_core__check_in_cover_prices as (
select * from {{ ref("int_core__check_in_cover_prices") }}
@ -121,9 +128,9 @@ with
select
vr.id_verification_request,
vr.uuid_verification_request,
vr.id_verification_set,
vr.id_superhog_verified_set,
vr.id_payment_validation_set,
null as id_verification_set,
null as id_superhog_verified_set,
null as id_payment_validation_set,
vr.id_user_guest,
vr.id_user_host,
b.id_booking,
@ -187,33 +194,45 @@ with
p.amount_without_taxes_in_txn_currency,
p.total_amount_in_gbp,
p.amount_without_taxes_in_gbp,
ccp.checkin_cover_limit_amount_local_curr,
gpcpp.protection_limit_in_local_currency
as checkin_cover_limit_amount_local_curr,
(
ccp.checkin_cover_limit_amount_local_curr
gpcpp.protection_limit_in_local_currency
* (p.total_amount_in_gbp / p.total_amount_in_txn_currency)
)::numeric(18, 4) as checkin_cover_limit_amount_in_gbp
from int_core__verification_requests vr
inner join
stg_core__verification_request_to_guest_product vrtogp
on vr.id_verification_request = vrtogp.id_verification_request
inner join
stg_core__guest_product_configuration_price_plan gpcpp
on vrtogp.id_guest_product_configuration_price_plan
= gpcpp.id_guest_product_configuration_price_plan
inner join stg_core__currency c on c.id_currency = gpcpp.id_currency
left join
int_core__bookings b
on vr.id_verification_request = b.id_verification_request
left join
stg_core__verification_set_to_verification_type vstvt
on vr.id_verification_set = vstvt.id_verification_set
left join
check_in_cover_payments p
on vr.id_verification_request = p.id_verification_request
left join
int_core__check_in_cover_prices ccp
on p.currency = ccp.local_currency_iso_4217
left join int_core__unified_user gu on gu.id_user = vr.id_user_guest
-- 15 is Check-in cover.
-- Adding this condition results in only keeping guest journeys that offered the
-- check-in cover
where vstvt.id_verification_type = 99
where
p.currency = c.iso4217_code
and vrtogp.id_guest_product = 2 -- 2 is CIH
and vr.link_used_at_utc
>= {{ var("guest_products_feature_flag_activation_timestamp") }} -- This logic path only applies to VRs started after the FF was activated
)
select *
from pre_feature_flag_verification_requests
{%- if modules.datetime.datetime.now(
modules.pytz.timezone("UTC")
) > modules.datetime.datetime.strptime(
var("guest_products_feature_flag_activation_timestamp"),
"'%Y-%m-%dT%H:%M:%S%z'",
) -%}
union all
select *
from post_feature_flag_verification_requests
{% endif %}