Simplify PR
This commit is contained in:
parent
79b408f3d2
commit
19d883ccd7
9 changed files with 52 additions and 209 deletions
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
with
|
with
|
||||||
stg_core__apim_user as (select * from {{ ref("stg_core__apim_user") }}),
|
stg_core__apim_user as (select * from {{ ref("stg_core__apim_user") }}),
|
||||||
stg_core__apim_user_type as (select * from {{ ref("stg_core__apim_user_type") }})
|
stg_core__apim_user_type as (select * from {{ ref("stg_core__apim_user_type") }}),
|
||||||
|
stg_core__user as (select * from {{ ref("stg_core__user") }})
|
||||||
select
|
select
|
||||||
au.id_apim_user,
|
au.id_apim_user,
|
||||||
au.id_apim_user_type,
|
au.id_apim_user_type,
|
||||||
|
u.id_account_currency as id_currency,
|
||||||
au.json_document_user_data ->> 'DealId' as id_deal,
|
au.json_document_user_data ->> 'DealId' as id_deal,
|
||||||
au.json_document_user_data ->> 'AccountType' as account_type,
|
au.json_document_user_data ->> 'AccountType' as account_type,
|
||||||
au.json_document_user_data ->> 'ClientMarkup' as client_markup,
|
au.json_document_user_data ->> 'ClientMarkup' as client_markup,
|
||||||
|
|
@ -42,3 +44,4 @@ inner join
|
||||||
stg_core__apim_user_type aut
|
stg_core__apim_user_type aut
|
||||||
on au.id_apim_user_type = aut.id_apim_user_type
|
on au.id_apim_user_type = aut.id_apim_user_type
|
||||||
and upper(aut.user_type_name) = '{{ api_name }}'
|
and upper(aut.user_type_name) = '{{ api_name }}'
|
||||||
|
inner join stg_core__user u on au.id_apim_user = u.id_user
|
||||||
|
|
|
||||||
|
|
@ -4590,6 +4590,16 @@ models:
|
||||||
data_type: bigint
|
data_type: bigint
|
||||||
description: "Identifier of the type of user."
|
description: "Identifier of the type of user."
|
||||||
|
|
||||||
|
- name: id_currency
|
||||||
|
data_type: bigint
|
||||||
|
description: "Id of the currency, works as a foreign key to the
|
||||||
|
currency table"
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- relationships:
|
||||||
|
to: ref('stg_core__currency')
|
||||||
|
field: id_currency
|
||||||
|
|
||||||
- name: id_deal
|
- name: id_deal
|
||||||
data_type: text
|
data_type: text
|
||||||
description: ""
|
description: ""
|
||||||
|
|
|
||||||
|
|
@ -1,185 +0,0 @@
|
||||||
{% set rejected_status = "REJECTED" %}
|
|
||||||
{% set approved_flagged_status = ("APPROVED", "FLAGGED") %}
|
|
||||||
{% set basic_protection = "BASIC PROTECTION" %}
|
|
||||||
{% set damage_waiver = "DAMAGE WAIVER" %}
|
|
||||||
{% set screen_and_protect = "SCREEN & PROTECT" %}
|
|
||||||
{% set standalone_protection = "STANDALONE PROTECTION" %}
|
|
||||||
{% set cancel_rejected_fee = 0.25 %}
|
|
||||||
{% set long_stay_booking = 30 %}
|
|
||||||
|
|
||||||
with
|
|
||||||
int_screen_and_protect__verification_requests as (
|
|
||||||
select * from {{ ref("int_screen_and_protect__verification_requests") }}
|
|
||||||
),
|
|
||||||
stg_core__basic_protection as (
|
|
||||||
select * from {{ ref("stg_core__basic_protection") }}
|
|
||||||
),
|
|
||||||
stg_core__damage_waiver as (select * from {{ ref("stg_core__damage_waiver") }}),
|
|
||||||
stg_core__screen_and_protect as (
|
|
||||||
select * from {{ ref("stg_core__screen_and_protect") }}
|
|
||||||
),
|
|
||||||
stg_core__standalone_protection as (
|
|
||||||
select * from {{ ref("stg_core__standalone_protection") }}
|
|
||||||
),
|
|
||||||
active_discount_timeframe as (
|
|
||||||
select distinct
|
|
||||||
vr.id_user_partner,
|
|
||||||
date_trunc('month', vr.checkout_date_utc) as verification_month,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
date_trunc('month', vr.checkout_date_utc)
|
|
||||||
between vr.monthly_general_discount_start_date_utc
|
|
||||||
and vr.monthly_general_discount_end_date_utc
|
|
||||||
then 1
|
|
||||||
else 0
|
|
||||||
end as is_monthly_general_discount_active,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
date_trunc('month', vr.checkout_date_utc)
|
|
||||||
between vr.monthly_volume_discount_start_date_utc
|
|
||||||
and vr.monthly_volume_discount_end_date_utc
|
|
||||||
then 1
|
|
||||||
else 0
|
|
||||||
end as is_monthly_volume_discount_on,
|
|
||||||
vr.threshold_approved_booking_volume,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
date_trunc('month', vr.checkout_date_utc)
|
|
||||||
>= vr.price_increase_start_date_utc
|
|
||||||
then 1
|
|
||||||
else 0
|
|
||||||
end as is_price_increase_active
|
|
||||||
from int_screen_and_protect__verification_requests vr
|
|
||||||
where upper(vr.verification_status) in {{ approved_flagged_status }}
|
|
||||||
),
|
|
||||||
approved_verifications as (
|
|
||||||
select
|
|
||||||
vr.id_user_partner,
|
|
||||||
date_trunc('month', vr.checkout_date_utc) as verification_month,
|
|
||||||
count(*) as monthly_verifications
|
|
||||||
from int_screen_and_protect__verification_requests vr
|
|
||||||
where upper(vr.verification_status) in {{ approved_flagged_status }}
|
|
||||||
group by vr.id_user_partner, date_trunc('month', vr.checkout_date_utc)
|
|
||||||
),
|
|
||||||
active_discounts as (
|
|
||||||
select
|
|
||||||
av.id_user_partner,
|
|
||||||
av.verification_month,
|
|
||||||
av.monthly_verifications,
|
|
||||||
adt.is_monthly_general_discount_active,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
av.monthly_verifications >= adt.threshold_approved_booking_volume
|
|
||||||
and adt.is_monthly_volume_discount_on = 1
|
|
||||||
then 1
|
|
||||||
else 0
|
|
||||||
end as is_monthly_volume_discount_active,
|
|
||||||
adt.is_price_increase_active
|
|
||||||
from approved_verifications av
|
|
||||||
left join
|
|
||||||
active_discount_timeframe adt
|
|
||||||
on av.id_user_partner = adt.id_user_partner
|
|
||||||
and av.verification_month = adt.verification_month
|
|
||||||
)
|
|
||||||
select
|
|
||||||
vr.id_verification,
|
|
||||||
vr.id_booking,
|
|
||||||
vr.id_user_partner,
|
|
||||||
vr.id_accommodation,
|
|
||||||
vr.is_protected,
|
|
||||||
vr.protection_type,
|
|
||||||
vr.verification_status,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
vr.number_of_nights > {{ long_stay_booking }}
|
|
||||||
and upper(vr.verification_status) in {{ approved_flagged_status }}
|
|
||||||
and vr.is_protected is true
|
|
||||||
then
|
|
||||||
bp.long_stay_fee_in_local_currency
|
|
||||||
* vr.number_of_nights
|
|
||||||
* (1 + vr.price_increase / 100 * ad.is_price_increase_active)
|
|
||||||
* (
|
|
||||||
1
|
|
||||||
- vr.monthly_volume_discount
|
|
||||||
/ 100
|
|
||||||
* ad.is_monthly_volume_discount_active
|
|
||||||
)
|
|
||||||
* (
|
|
||||||
1
|
|
||||||
- vr.monthly_general_discount
|
|
||||||
/ 100
|
|
||||||
* ad.is_monthly_general_discount_active
|
|
||||||
+ vr.price_increase / 100 * ad.is_price_increase_active
|
|
||||||
)
|
|
||||||
when
|
|
||||||
upper(vr.verification_status) in {{ approved_flagged_status }}
|
|
||||||
and vr.is_protected is true
|
|
||||||
then
|
|
||||||
bp.short_stay_fee_in_local_currency
|
|
||||||
* vr.number_of_nights
|
|
||||||
* (1 + vr.price_increase / 100 * ad.is_price_increase_active)
|
|
||||||
* (
|
|
||||||
1
|
|
||||||
- vr.monthly_volume_discount
|
|
||||||
/ 100
|
|
||||||
* ad.is_monthly_volume_discount_active
|
|
||||||
)
|
|
||||||
* (
|
|
||||||
1
|
|
||||||
- vr.monthly_general_discount
|
|
||||||
/ 100
|
|
||||||
* ad.is_monthly_general_discount_active
|
|
||||||
+ vr.price_increase / 100 * ad.is_price_increase_active
|
|
||||||
)
|
|
||||||
else 0
|
|
||||||
end as booking_fee_in_local_currency,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
upper(vr.verification_status) = '{{ rejected_status }}'
|
|
||||||
or vr.is_cancelled = true
|
|
||||||
or vr.is_protected is false
|
|
||||||
then {{ cancel_rejected_fee }}
|
|
||||||
else 0
|
|
||||||
end as cancel_or_rejected_fee_in_local_currency,
|
|
||||||
case
|
|
||||||
when
|
|
||||||
upper(vr.verification_status) = '{{ rejected_status }}'
|
|
||||||
or vr.is_cancelled = true
|
|
||||||
then creation_date_utc
|
|
||||||
else checkout_date_utc
|
|
||||||
end as invoice_date_utc,
|
|
||||||
vr.id_currency,
|
|
||||||
vr.checkin_date_utc,
|
|
||||||
vr.checkout_date_utc,
|
|
||||||
vr.number_of_nights,
|
|
||||||
vr.is_cancelled,
|
|
||||||
vr.cancelled_at_utc,
|
|
||||||
vr.cancelled_date_utc,
|
|
||||||
vr.user_email,
|
|
||||||
vr.company_name,
|
|
||||||
vr.property_manager_name,
|
|
||||||
vr.property_manager_email,
|
|
||||||
vr.listing_name,
|
|
||||||
vr.listing_address,
|
|
||||||
vr.listing_town,
|
|
||||||
vr.listing_country,
|
|
||||||
vr.listing_postcode,
|
|
||||||
vr.pets_allowed,
|
|
||||||
vr.status_updated_at_utc,
|
|
||||||
vr.status_updated_date_utc,
|
|
||||||
vr.updated_at_utc,
|
|
||||||
vr.updated_date_utc,
|
|
||||||
vr.creation_at_utc,
|
|
||||||
vr.creation_date_utc,
|
|
||||||
vr.cosmos_created_date_utc
|
|
||||||
from int_screen_and_protect__verification_requests vr
|
|
||||||
inner join
|
|
||||||
stg_core__basic_protection bp
|
|
||||||
on vr.id_currency = bp.id_currency
|
|
||||||
and vr.protection_basic_amount_in_local_currency
|
|
||||||
= bp.protection_basic_amount_in_local_currency
|
|
||||||
inner join
|
|
||||||
active_discounts ad
|
|
||||||
on vr.id_user_partner = ad.id_user_partner
|
|
||||||
and date_trunc('month', vr.checkout_date_utc) = ad.verification_month
|
|
||||||
where upper(vr.protection_type) = '{{ basic_protection }}'
|
|
||||||
|
|
@ -4,19 +4,18 @@ with
|
||||||
),
|
),
|
||||||
int_core__screen_and_protect_users as (
|
int_core__screen_and_protect_users as (
|
||||||
select * from {{ ref("int_core__screen_and_protect_users") }}
|
select * from {{ ref("int_core__screen_and_protect_users") }}
|
||||||
),
|
)
|
||||||
stg_core__user as (select * from {{ ref("stg_core__user") }})
|
|
||||||
select
|
select
|
||||||
vr.id_verification,
|
vr.id_verification,
|
||||||
vr.id_booking,
|
vr.id_booking,
|
||||||
vr.id_user_partner,
|
vr.id_user_partner,
|
||||||
vr.id_accommodation,
|
vr.id_accommodation,
|
||||||
u.id_account_currency as id_currency,
|
spu.id_currency,
|
||||||
spu.is_protected,
|
spu.is_protected,
|
||||||
vr.protection_type,
|
vr.protection_type,
|
||||||
vr.protection_starting_level as protection_starting_level_in_local_currency,
|
vr.protection_starting_amount_in_local_currency,
|
||||||
vr.protection_basic_amount as protection_basic_amount_in_local_currency,
|
vr.protection_basic_amount_in_local_currency,
|
||||||
vr.protection_extended_amount as protection_extended_amount_in_local_currency,
|
vr.protection_extended_amount_in_local_currency,
|
||||||
vr.pet_protection,
|
vr.pet_protection,
|
||||||
vr.verification_status,
|
vr.verification_status,
|
||||||
vr.verification_status_reason,
|
vr.verification_status_reason,
|
||||||
|
|
@ -63,4 +62,3 @@ select
|
||||||
from stg_screen_and_protect__verification_requests vr
|
from stg_screen_and_protect__verification_requests vr
|
||||||
inner join
|
inner join
|
||||||
int_core__screen_and_protect_users spu on vr.id_user_partner = spu.id_apim_user
|
int_core__screen_and_protect_users spu on vr.id_user_partner = spu.id_apim_user
|
||||||
inner join stg_core__user u on spu.id_apim_user = u.id_user
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,16 @@ models:
|
||||||
data_type: text
|
data_type: text
|
||||||
description: Identifier for the accommodation related to the booking.
|
description: Identifier for the accommodation related to the booking.
|
||||||
|
|
||||||
|
- name: id_currency
|
||||||
|
data_type: bigint
|
||||||
|
description: "Id of the currency, works as a foreign key to the
|
||||||
|
currency table"
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- relationships:
|
||||||
|
to: ref('stg_core__currency')
|
||||||
|
field: id_currency
|
||||||
|
|
||||||
- name: is_protected
|
- name: is_protected
|
||||||
data_type: boolean
|
data_type: boolean
|
||||||
description: |
|
description: |
|
||||||
|
|
@ -55,7 +65,7 @@ models:
|
||||||
- "DAMAGE WAIVER"
|
- "DAMAGE WAIVER"
|
||||||
- "PET PROTECTION"
|
- "PET PROTECTION"
|
||||||
|
|
||||||
- name: protection_starting_level_in_local_currency
|
- name: protection_starting_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "STANDALONE PROTECTION" to
|
description: Field used for protection type "STANDALONE PROTECTION" to
|
||||||
indicate the starting level of protection.
|
indicate the starting level of protection.
|
||||||
|
|
|
||||||
|
|
@ -50,30 +50,33 @@ models:
|
||||||
- "DAMAGE WAIVER"
|
- "DAMAGE WAIVER"
|
||||||
- "PET PROTECTION"
|
- "PET PROTECTION"
|
||||||
|
|
||||||
- name: protection_starting_level
|
- name: protection_starting_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "STANDALONE PROTECTION" to
|
description: Field used for protection type "STANDALONE PROTECTION" to
|
||||||
indicate the starting level of protection.
|
indicate the starting level of protection.
|
||||||
|
In local currency.
|
||||||
tests:
|
tests:
|
||||||
- dbt_expectations.expect_column_values_to_be_between:
|
- dbt_expectations.expect_column_values_to_be_between:
|
||||||
min_value: 0
|
min_value: 0
|
||||||
max_value: 100000
|
max_value: 100000
|
||||||
strictly: true
|
strictly: true
|
||||||
|
|
||||||
- name: protection_basic_amount
|
- name: protection_basic_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "SCREEN & PROTECT",
|
description: Field used for protection type "SCREEN & PROTECT",
|
||||||
"BASIC PROTECTION" or "DAMAGE WAIVER" to show the basic amount of protection.
|
"BASIC PROTECTION" or "DAMAGE WAIVER" to show the basic amount of protection.
|
||||||
|
In local currency.
|
||||||
tests:
|
tests:
|
||||||
- dbt_expectations.expect_column_values_to_be_between:
|
- dbt_expectations.expect_column_values_to_be_between:
|
||||||
min_value: 0
|
min_value: 0
|
||||||
max_value: 100000
|
max_value: 100000
|
||||||
strictly: true
|
strictly: true
|
||||||
|
|
||||||
- name: protection_extended_amount
|
- name: protection_extended_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "SCREEN & PROTECT",
|
description: Field used for protection type "SCREEN & PROTECT",
|
||||||
or "STANDALONE PROTECTION" to show the basic amount of protection.
|
or "STANDALONE PROTECTION" to show the basic amount of protection.
|
||||||
|
In local currency.
|
||||||
tests:
|
tests:
|
||||||
- dbt_expectations.expect_column_values_to_be_between:
|
- dbt_expectations.expect_column_values_to_be_between:
|
||||||
min_value: 0
|
min_value: 0
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,18 @@ with
|
||||||
select * from {{ ref("int_screen_and_protect__verification_requests") }}
|
select * from {{ ref("int_screen_and_protect__verification_requests") }}
|
||||||
)
|
)
|
||||||
select
|
select
|
||||||
-- note that these ids are not the same as the ones found in Core DWH
|
|
||||||
-- they are completely unrelated
|
|
||||||
id_verification as id_verification,
|
id_verification as id_verification,
|
||||||
id_booking as id_booking,
|
id_booking as id_booking,
|
||||||
id_user_partner as id_user_partner,
|
id_user_partner as id_user_partner,
|
||||||
id_accommodation as id_accommodation,
|
id_accommodation as id_accommodation,
|
||||||
is_protected as is_protected,
|
is_protected as is_protected,
|
||||||
protection_type as protection_type,
|
protection_type as protection_type,
|
||||||
protection_starting_level as protection_starting_level,
|
protection_starting_amount_in_local_currency
|
||||||
protection_basic_amount as protection_basic_amount,
|
as protection_starting_amount_in_local_currency,
|
||||||
protection_extended_amount as protection_extended_amount,
|
protection_basic_amount_in_local_currency
|
||||||
|
as protection_basic_amount_in_local_currency,
|
||||||
|
protection_extended_amount_in_local_currency
|
||||||
|
as protection_extended_amount_in_local_currency,
|
||||||
pet_protection as pet_protection,
|
pet_protection as pet_protection,
|
||||||
verification_status as verification_status,
|
verification_status as verification_status,
|
||||||
verification_status_reason as verification_status_reason,
|
verification_status_reason as verification_status_reason,
|
||||||
|
|
|
||||||
|
|
@ -43,30 +43,33 @@ models:
|
||||||
- "DAMAGE WAIVER"
|
- "DAMAGE WAIVER"
|
||||||
- "PET PROTECTION"
|
- "PET PROTECTION"
|
||||||
|
|
||||||
- name: protection_starting_level
|
- name: protection_starting_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "STANDALONE PROTECTION" to
|
description: Field used for protection type "STANDALONE PROTECTION" to
|
||||||
indicate the starting level of protection.
|
indicate the starting amount of protection.
|
||||||
|
In local currency.
|
||||||
tests:
|
tests:
|
||||||
- dbt_expectations.expect_column_values_to_be_between:
|
- dbt_expectations.expect_column_values_to_be_between:
|
||||||
min_value: 0
|
min_value: 0
|
||||||
max_value: 100000
|
max_value: 100000
|
||||||
strictly: true
|
strictly: true
|
||||||
|
|
||||||
- name: protection_basic_amount
|
- name: protection_basic_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "SCREEN & PROTECT",
|
description: Field used for protection type "SCREEN & PROTECT",
|
||||||
"BASIC PROTECTION" or "DAMAGE WAIVER" to show the basic amount of protection.
|
"BASIC PROTECTION" or "DAMAGE WAIVER" to show the basic amount of protection.
|
||||||
|
In local currency.
|
||||||
tests:
|
tests:
|
||||||
- dbt_expectations.expect_column_values_to_be_between:
|
- dbt_expectations.expect_column_values_to_be_between:
|
||||||
min_value: 0
|
min_value: 0
|
||||||
max_value: 100000
|
max_value: 100000
|
||||||
strictly: true
|
strictly: true
|
||||||
|
|
||||||
- name: protection_extended_amount
|
- name: protection_extended_amount_in_local_currency
|
||||||
data_type: numeric
|
data_type: numeric
|
||||||
description: Field used for protection type "SCREEN & PROTECT",
|
description: Field used for protection type "SCREEN & PROTECT",
|
||||||
or "STANDALONE PROTECTION" to show the basic amount of protection.
|
or "STANDALONE PROTECTION" to show the basic amount of protection.
|
||||||
|
In local currency.
|
||||||
tests:
|
tests:
|
||||||
- dbt_expectations.expect_column_values_to_be_between:
|
- dbt_expectations.expect_column_values_to_be_between:
|
||||||
min_value: 0
|
min_value: 0
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ with
|
||||||
then null
|
then null
|
||||||
else {{ adapter.quote("documents") }} ->> 'ProtectionStartingLevel'
|
else {{ adapter.quote("documents") }} ->> 'ProtectionStartingLevel'
|
||||||
end as decimal(19, 4)
|
end as decimal(19, 4)
|
||||||
) as protection_starting_level,
|
) as protection_starting_amount_in_local_currency,
|
||||||
cast(
|
cast(
|
||||||
case
|
case
|
||||||
when
|
when
|
||||||
|
|
@ -31,7 +31,7 @@ with
|
||||||
then null
|
then null
|
||||||
else {{ adapter.quote("documents") }} ->> 'ProtectionBasicAmount'
|
else {{ adapter.quote("documents") }} ->> 'ProtectionBasicAmount'
|
||||||
end as decimal(19, 4)
|
end as decimal(19, 4)
|
||||||
) as protection_basic_amount,
|
) as protection_basic_amount_in_local_currency,
|
||||||
cast(
|
cast(
|
||||||
case
|
case
|
||||||
when
|
when
|
||||||
|
|
@ -40,7 +40,7 @@ with
|
||||||
then null
|
then null
|
||||||
else {{ adapter.quote("documents") }} ->> 'ProtectionExtendedAmount'
|
else {{ adapter.quote("documents") }} ->> 'ProtectionExtendedAmount'
|
||||||
end as decimal(19, 4)
|
end as decimal(19, 4)
|
||||||
) as protection_extended_amount,
|
) as protection_extended_amount_in_local_currency,
|
||||||
({{ adapter.quote("documents") }} ->> 'PetProtection')::boolean
|
({{ adapter.quote("documents") }} ->> 'PetProtection')::boolean
|
||||||
as pet_protection,
|
as pet_protection,
|
||||||
upper({{ adapter.quote("documents") }} ->> 'Status') as verification_status,
|
upper({{ adapter.quote("documents") }} ->> 'Status') as verification_status,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue