diff --git a/models/intermediate/core/int_core__guest_product_price_plans.sql b/models/intermediate/core/int_core__guest_product_price_plans.sql new file mode 100644 index 0000000..21343ea --- /dev/null +++ b/models/intermediate/core/int_core__guest_product_price_plans.sql @@ -0,0 +1,56 @@ +with + stg_core__guest_product_configuration_price_plan as ( + select * from {{ ref("stg_core__guest_product_configuration_price_plan") }} + ), + stg_core__currency as (select * from {{ ref("stg_core__currency") }}), + stg_core__guest_product_configuration as ( + select * from {{ ref("stg_core__guest_product_configuration") }} + ), + int_core__guest_products as (select * from {{ ref("int_core__guest_products") }}), + price_plan_with_end_date as ( + select + id_guest_product_configuration_price_plan, + id_guest_product_configuration, + id_currency, + product_price_in_local_currency, + protection_limit_in_local_currency, + starts_at_utc, + start_date_utc, + created_at_utc, + created_date_utc, + updated_at_utc, + updated_date_utc, + lead(starts_at_utc) over ( + partition by id_guest_product_configuration, id_currency + order by starts_at_utc desc + ) as ends_at_utc + from stg_core__guest_product_configuration_price_plan + ) +select + ppwed.id_guest_product_configuration_price_plan, + ppwed.id_guest_product_configuration, + icgp.guest_product_name, + icgp.guest_product_latest_display_name, + scgpc.configuration_level as configuration_level, + scgpc.id_user_host, + scc.iso4217_code as currency_code, + ppwed.product_price_in_local_currency, + ppwed.protection_limit_in_local_currency, + ppwed.starts_at_utc, + ppwed.start_date_utc, + coalesce(ppwed.ends_at_utc, {{ var("end_of_time") }}::timestamp) as ends_at_utc, + coalesce(date(ppwed.ends_at_utc), {{ var("end_of_time") }}) as end_date_utc, + case + when ppwed.ends_at_utc is null then true else false + end as is_latest_price_plan, + ppwed.created_at_utc, + ppwed.created_date_utc, + ppwed.updated_at_utc, + ppwed.updated_date_utc +from price_plan_with_end_date ppwed +left join stg_core__currency scc on ppwed.id_currency = scc.id_currency +left join + stg_core__guest_product_configuration scgpc + on ppwed.id_guest_product_configuration = scgpc.id_guest_product_configuration +left join + int_core__guest_products icgp on scgpc.id_guest_product = icgp.id_guest_product diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 56fef64..24a7822 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -5914,3 +5914,173 @@ models: description: | Date of when the guest product display name started to be in use. This is purely for information purposes. + + - name: int_core__guest_product_price_plans + description: | + Master table of Pricing for Guest Products. + Contains the information of the guest product, whether if it corresponds + to a default pricing or a custom pricing for a given host and + whether the product itself is currently available and if it is available + for Guest Journey purposes or not. For each case, a specific product price + and protection limit is displayed for all working currencies. + Historical price plans are also reflected here, so keep this in mind + when querying this model. + + columns: + - name: id_guest_product_configuration_price_plan + data_type: bigint + description: | + Unique identifier of the guest product configuration price plan. + Acts as the primary key for this table. + data_tests: + - not_null + - unique + + - name: id_guest_product_configuration + data_type: bigint + description: | + Identifier of the guest product configuration. + data_tests: + - not_null + + - name: guest_product_name + data_type: character varying + description: | + Internal name of the guest product. This is the + name used in internal configurations within our + systems. Only a single guest product name can exist + for a given product, opposite to the guest product display + name. + Recommended for building dedicated guest product logic. + It cannot be null. + data_tests: + - not_null + + - name: guest_product_latest_display_name + data_type: character varying + description: | + Latest display name of the guest product. This is the + commercial or client-facing name. + If multiple commercial names exist for a given guest + product, then only the last one is available. + Recommended for reporting purposes. + It cannot be null. + data_tests: + - not_null + + - name: configuration_level + data_type: string + description: | + Level of the configuration. It can correspond to + an account-based configuration (custom) or the + default configuration. + It cannot be null. + data_tests: + - not_null + - accepted_values: + values: + - DEFAULT + - ACCOUNT + + - name: id_user_host + data_type: text + description: | + Id of the user that acts as Host. + This field can be null if the configuration is the + default configuration. If it's set, it means this + configuration is a custom configuration. + + - name: currency_code + data_type: text + description: + Currency iso4217 code. It identifies the currency for the amount stated in + product_price_in_local_currency and protection_limit_in_local_currency. + It cannot be null. + data_tests: + - not_null + + - name: product_price_in_local_currency + data_type: numeric + description: | + Price of the guest product in local currency. + data_tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: true + + - name: protection_limit_in_local_currency + data_type: numeric + description: | + Protection limit in local currency, or covered amount. + data_tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: true + + - name: starts_at_utc + data_type: timestamp + description: | + Timestamp of when this configuration price plan starts. + data_tests: + - not_null + + - name: ends_at_utc + data_type: timestamp + description: | + Timestamp of when this configuration price plan ends. + data_tests: + - not_null + + - name: start_date_utc + data_type: date + description: | + Date of when this configuration price plan starts. + data_tests: + - not_null + + - name: end_date_utc + data_type: date + description: | + Date of when this configuration price plan ends. + data_tests: + - not_null + + - name: is_latest_price_plan + data_type: boolean + description: | + If true, it means this is the latest price plan for a given + configuration. If false, then this is an historical price plan + that has been overriden with a new plan. + It cannot be null. + data_tests: + - not_null + + - name: created_at_utc + data_type: timestamp + description: | + Timestamp of when this record was created. + data_tests: + - not_null + + - name: created_date_utc + data_type: date + description: | + Date of when this record was created. + data_tests: + - not_null + + - name: updated_at_utc + data_type: timestamp + description: | + Timestamp of when this record was last updated. + data_tests: + - not_null + + - name: updated_date_utc + data_type: date + description: | + Date of when this record was last updated. + data_tests: + - not_null diff --git a/models/staging/core/schema.yml b/models/staging/core/schema.yml index 5592630..898a045 100644 --- a/models/staging/core/schema.yml +++ b/models/staging/core/schema.yml @@ -2035,6 +2035,14 @@ models: - DEFAULT - ACCOUNT + - name: id_user_host + data_type: character varying + description: | + Id of the user that acts as Host. + This field can be null if the configuration is the + default configuration. If it's set, it means this + configuration is a custom configuration. + - name: created_at_utc data_type: timestamp description: |