Merged PR 2870: Add core.PayAway to staging

# Description

This PR brings the core table `PayAway` into staging, adds documentation and tests.

We are bringing this so we can build right until we reach `int_core__verification_payments_v2`, which needs this info to determine if a waiver was a Superhog-takes-risk type or Host-takes-risk type.

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #20043
This commit is contained in:
Pablo Martín 2024-09-17 09:59:26 +00:00
commit 07db97b79e
3 changed files with 153 additions and 1 deletions

View file

@ -232,4 +232,6 @@ sources:
- name: AccommodationToProductBundle
identifier: AccommodationToProductBundle
- name: ElectronicDepositUser
identifier: ElectronicDepositUser
identifier: ElectronicDepositUser
- name: PayAway
identifier: PayAway

View file

@ -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

View file

@ -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