diff --git a/models/staging/core/_core_sources.yml b/models/staging/core/_core_sources.yml index dccc25a..426a0bc 100644 --- a/models/staging/core/_core_sources.yml +++ b/models/staging/core/_core_sources.yml @@ -232,4 +232,6 @@ sources: - name: AccommodationToProductBundle identifier: AccommodationToProductBundle - name: ElectronicDepositUser - identifier: ElectronicDepositUser \ No newline at end of file + identifier: ElectronicDepositUser + - name: PayAway + identifier: PayAway diff --git a/models/staging/core/schema.yml b/models/staging/core/schema.yml index 5905c00..2dce224 100644 --- a/models/staging/core/schema.yml +++ b/models/staging/core/schema.yml @@ -391,3 +391,132 @@ models: data_type: timestamp description: | Timestamp of when this data was extracted into DWH. + - name: stg_core__payaway + description: | + Contains all the PayAway plans, which are basically the settings for + host-takes-waiver plans with our host customers. All plans have a start + and end point in time. + + As of today, though, the reality is that our monthly invoicing and + settlement process with hosts only looks at the payaway plan that was + active when a month finished. + + Plans can be open ended, as in not having a specified end in time. This + just means they are indefinitely active until someone changes it. + + Plans can also have a planned end time which sits in the future. + tests: + - dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B: + # The end timestamp should always be after the start timestamp + column_A: end_at_utc + column_B: start_at_utc + or_equal: False + - dbt_expectations.expect_column_pair_values_A_to_be_greater_than_B: + # The updated timestamp should always be equal or after the creation + # timestamp + column_A: updated_at_utc + column_B: created_at_utc + or_equal: True + + columns: + - name: id_payaway_plan + data_type: bigint + description: The unique id for this plan. + tests: + - unique + - not_null + + - name: id_currency + data_type: bigint + description: | + The Superhog ID of the currency that this record applies to. + tests: + - not_null + + - name: id_user_host + data_type: character varying + description: | + The Superhog ID of the host user this record applies to. + tests: + - not_null + + - name: start_at_utc + data_type: timestamp without time zone + description: | + The point in time in which this plan became active. It can never be + null. + tests: + - not_null + + - name: end_at_utc + data_type: timestamp without time zone + description: | + The point in time in which this plan will stop being active. It can be + null, which means the plan has no planned end date yet. Should this + column have a value, it should always be after the start time of the + plan. + + - name: has_no_end_date + data_type: boolean + description: | + Syntactic sugar for checking if the plan has a specified end date. + tests: + - not_null + + - name: payaway_percentage + data_type: numeric + description: | + The percentage of the Waiver payments that Superhog will keep as a + a fee. Should be between 0% and a 100%. 0% is a valid amount. + + This means that the Superhog fee is computed as: + Waiver Amount * payaway_percentage. + + If the amount that comes out of this calculation is smaller than the + amount in column payaway_minimum_commission_local_curr, then the + Superhog fee becomes payaway_minimum_commission_local_curr instead. + So, the final logic becomes: + MAX( + Waiver Amount * payaway_percentage, + payaway_minimum_commission_local_curr + ) + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1 + strictly: false + + - name: payaway_minimum_commission_local_curr + data_type: numeric + description: | + The minimum fee that we take from each waiver payment, specified in + the currency of the guest payment (so if this record is in dollars, it + means it applies to guest payments made in dollars). We will never + charge less than this. This can be 0. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: created_at_utc + data_type: timestamp + description: | + Timestamp of when the pay away plan was created. + tests: + - not_null + + - name: updated_at_utc + data_type: timestamp + description: | + Timestamp of when the pay away plan to currency was last updated + tests: + - not_null + + - name: dwh_extracted_at_utc + data_type: timestamp + description: | + Timestamp of when this data was extracted into DWH. + tests: + - not_null diff --git a/models/staging/core/stg_core__payaway.sql b/models/staging/core/stg_core__payaway.sql new file mode 100644 index 0000000..115ef7e --- /dev/null +++ b/models/staging/core/stg_core__payaway.sql @@ -0,0 +1,21 @@ +with + raw_payaway as (select * from {{ source("core", "PayAway") }}), + stg_core__payaway as ( + select + {{ adapter.quote("Id") }} as id_payaway_plan, + {{ adapter.quote("CurrencyId") }} as id_currency, + {{ adapter.quote("SuperhogUserId") }} as id_user_host, + {{ adapter.quote("StartDate") }} as start_at_utc, + {{ adapter.quote("EndDate") }} as end_at_utc, + {{ adapter.quote("EndDate") }} is null as has_no_end_date, + {{ adapter.quote("PayAwayPercentage") }} as payaway_percentage, + {{ adapter.quote("PayAwayMinimumCommission") }} + as payaway_minimum_commission_local_curr, + {{ adapter.quote("CreatedDate") }} as created_at_utc, + {{ adapter.quote("UpdatedDate") }} as updated_at_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_payaway + ) +select * +from stg_core__payaway