From 68c509050fa8988b29b8ab6744a60d5e01ead2e4 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 17 Sep 2024 10:32:11 +0200 Subject: [PATCH 1/5] add payway to sources --- models/staging/core/_core_sources.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 96d18116ed4edba8885b22adf66edbb2b69cbb8e Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 17 Sep 2024 10:36:43 +0200 Subject: [PATCH 2/5] add staging model --- models/staging/core/stg_core__PayAway.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 models/staging/core/stg_core__PayAway.sql 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 From 68a9eafb145a04910ed78e8c432f44eac5de8fff Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 17 Sep 2024 10:36:58 +0200 Subject: [PATCH 3/5] typo in file name --- .../staging/core/{stg_core__PayAway.sql => stg_core__payaway.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename models/staging/core/{stg_core__PayAway.sql => stg_core__payaway.sql} (100%) diff --git a/models/staging/core/stg_core__PayAway.sql b/models/staging/core/stg_core__payaway.sql similarity index 100% rename from models/staging/core/stg_core__PayAway.sql rename to models/staging/core/stg_core__payaway.sql From 624c70872fadc6194fe2ee53c0315e6b292d9da6 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 17 Sep 2024 11:16:01 +0200 Subject: [PATCH 4/5] docs and tests --- models/staging/core/schema.yml | 126 +++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/models/staging/core/schema.yml b/models/staging/core/schema.yml index 5905c00..542beef 100644 --- a/models/staging/core/schema.yml +++ b/models/staging/core/schema.yml @@ -391,3 +391,129 @@ 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, which means that any waivers that happen during + the range of plan should use the settings of this plan as a reference. + + 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 From 1c04c69e897cc6e49557941e8b3de24cd0c03ab0 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 17 Sep 2024 11:59:04 +0200 Subject: [PATCH 5/5] fix comments --- models/staging/core/schema.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/models/staging/core/schema.yml b/models/staging/core/schema.yml index 542beef..2dce224 100644 --- a/models/staging/core/schema.yml +++ b/models/staging/core/schema.yml @@ -395,8 +395,11 @@ models: 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, which means that any waivers that happen during - the range of plan should use the settings of this plan as a reference. + 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.