From 0aaec6a619c049298d1aa3e50006e992ffb2f1ff Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Sep 2024 16:36:19 +0200 Subject: [PATCH 01/19] fuck around with Uri --- .../core/int_core__verification_payments.sql | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments.sql b/models/intermediate/core/int_core__verification_payments.sql index ac4bb23..44e4051 100644 --- a/models/intermediate/core/int_core__verification_payments.sql +++ b/models/intermediate/core/int_core__verification_payments.sql @@ -7,10 +7,15 @@ with select * from {{ ref("stg_core__verification_payment_type") }} ), stg_core__verification as (select * from {{ ref("stg_core__verification") }}), - stg_core__verification_request as (select * from {{ ref("stg_core__verification_request") }}), + stg_core__verification_request as ( + select * from {{ ref("stg_core__verification_request") }} + ), stg_core__payment as (select * from {{ ref("stg_core__payment") }}), stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}), - int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}) + int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}), + stg_seed__guest_services_vat_rates_by_country as ( + select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }} + ) select vtp.id_verification_to_payment, vtp.id_payment, @@ -30,6 +35,9 @@ select -- Host User identifier is included to speed up -- KPIs execution, even though the host itself -- has nothing to do with the guest payments. + -- --------------------------------------------- + -- Pablo here, I promise I'll find a way to improve performance and get rid + -- of this uglyness. Oh god, it hurts. vr.id_user_host, vtp.id_guest_user, vtp.id_verification, @@ -52,6 +60,6 @@ left join on vtp.payment_due_date_utc = r.rate_date_utc and p.currency = r.from_currency and r.to_currency = 'GBP' -left join - stg_core__verification_request vr - on v.id_verification_request = vr.id_verification_request \ No newline at end of file +left join + stg_core__verification_request vr + on v.id_verification_request = vr.id_verification_request From bde6f12404791bd0e41531cb23de5f9469b9eb06 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Sep 2024 16:59:46 +0200 Subject: [PATCH 02/19] add new columns --- .../core/int_core__verification_payments.sql | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/models/intermediate/core/int_core__verification_payments.sql b/models/intermediate/core/int_core__verification_payments.sql index 44e4051..5afd344 100644 --- a/models/intermediate/core/int_core__verification_payments.sql +++ b/models/intermediate/core/int_core__verification_payments.sql @@ -13,6 +13,7 @@ with stg_core__payment as (select * from {{ ref("stg_core__payment") }}), stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}), int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}), + int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), stg_seed__guest_services_vat_rates_by_country as ( select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }} ) @@ -43,9 +44,38 @@ select vtp.id_verification, v.id_verification_request, vpt.verification_payment_type, - p.amount as amount_in_txn_currency, p.currency, + p.amount as amount_in_txn_currency, (p.amount * r.rate) as amount_in_gbp, + p.amount as payment_amount_in_txn_currency, + (p.amount * r.rate) as payment_amount_in_gbp, + p.amount as total_amount_in_txn_currency, + (p.amount * r.rate) as total_amount_in_in_gbp, + /* + Helping comment for logic below. + Given that guest payments are tax inclusive, the tax (column + tax_amount_in_txn_currency) is calculated as: + paid by guest + tax = paid by guest - ( ------------- ) + 1 + VAT Rate + + The amount without tax (column amount_without_taxes_in_txn_currency) gets + calculated as: + paid by guest + amount without tax = ( ------------- ) + 1 + VAT Rate + */ + (p.amount - (p.amount / (1 + vat.vat_rates))) as tax_amount_in_txn_currency, + (p.amount - (p.amount / (1 + vat.vat_rates))) * r.rate as tax_amount_in_gbp, + (p.amount / (1 + vat.vat_rates)) as amount_without_taxes_in_txn_currency, + (p.amount / (1 + vat.vat_rates)) * r.rate as amount_without_taxes_in_gbp, + vat.vat_rate as applicable_vat_tax_rate, + case + when vat.vat_rate = 0 + then false + when vat.vat_rate < 1 and vat.vat_rate > 0 + then true + end as is_vat_taxed, ps.payment_status, p.notes from stg_core__verification_to_payment vtp @@ -63,3 +93,7 @@ left join left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request +left join int_core__unified_user uu on vtp.id_guest_user == uu.id_user +left join + stg_seed__guest_services_vat_rates_by_country vat + on uu.billing_country_iso_3 == vat.alpha_3 From 4ba6c80d6f6b25d9a8f4be524fb51b5e3fae8aed Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Sep 2024 17:19:30 +0200 Subject: [PATCH 03/19] v2 model --- .../int_core__verification_payments_v2.sql | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 models/intermediate/core/int_core__verification_payments_v2.sql diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql new file mode 100644 index 0000000..09d78aa --- /dev/null +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -0,0 +1,95 @@ +{{ config(materialized="table") }} +with + stg_core__verification_to_payment as ( + select * from {{ ref("stg_core__verification_to_payment") }} + ), + stg_core__verification_payment_type as ( + select * from {{ ref("stg_core__verification_payment_type") }} + ), + stg_core__verification as (select * from {{ ref("stg_core__verification") }}), + stg_core__verification_request as ( + select * from {{ ref("stg_core__verification_request") }} + ), + stg_core__payment as (select * from {{ ref("stg_core__payment") }}), + stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}), + int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}), + int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), + stg_seed__guest_services_vat_rates_by_country as ( + select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }} + ) +select + vtp.id_verification_to_payment, + vtp.id_payment, + vtp.is_refundable, + vtp.created_at_utc, + vtp.updated_at_utc, + vtp.payment_due_at_utc, + vtp.payment_due_date_utc, + p.paid_at_utc as payment_paid_at_utc, + p.paid_date_utc as payment_paid_date_utc, + p.payment_reference, + vtp.refund_due_at_utc, + vtp.refund_due_date_utc, + p.refunded_at_utc as payment_refunded_at_utc, + p.refunded_date_utc as payment_refunded_date_utc, + p.refund_payment_reference, + -- Host User identifier is included to speed up + -- KPIs execution, even though the host itself + -- has nothing to do with the guest payments. + -- --------------------------------------------- + -- Pablo here, I promise I'll find a way to improve performance and get rid + -- of this uglyness. Oh god, it hurts. + vr.id_user_host, + vtp.id_guest_user, + vtp.id_verification, + v.id_verification_request, + vpt.verification_payment_type, + p.currency, + p.amount as total_amount_in_txn_currency, + (p.amount * r.rate) as total_amount_in_in_gbp, + /* + Helping comment for logic below. + Given that guest payments are tax inclusive, the tax (column + tax_amount_in_txn_currency) is calculated as: + paid by guest + tax = paid by guest - ( ------------- ) + 1 + VAT Rate + + The amount without tax (column amount_without_taxes_in_txn_currency) gets + calculated as: + paid by guest + amount without tax = ( ------------- ) + 1 + VAT Rate + */ + (p.amount - (p.amount / (1 + vat.vat_rates))) as tax_amount_in_txn_currency, + (p.amount - (p.amount / (1 + vat.vat_rates))) * r.rate as tax_amount_in_gbp, + (p.amount / (1 + vat.vat_rates)) as amount_without_taxes_in_txn_currency, + (p.amount / (1 + vat.vat_rates)) * r.rate as amount_without_taxes_in_gbp, + vat.vat_rate as applicable_vat_tax_rate, + case + when vat.vat_rate = 0 + then false + when vat.vat_rate < 1 and vat.vat_rate > 0 + then true + end as is_vat_taxed, + ps.payment_status, + p.notes +from stg_core__verification_to_payment vtp +left join stg_core__payment p on vtp.id_payment = p.id_payment +left join stg_core__verification v on vtp.id_verification = v.id_verification +left join + stg_core__verification_payment_type vpt + on vtp.id_verification_payment_type = vpt.id_verification_payment_type +left join stg_core__payment_status ps on p.id_payment_status = ps.id_payment_status +left join + int_simple_exchange_rates r + on vtp.payment_due_date_utc = r.rate_date_utc + and p.currency = r.from_currency + and r.to_currency = 'GBP' +left join + stg_core__verification_request vr + on v.id_verification_request = vr.id_verification_request +left join int_core__unified_user uu on vtp.id_guest_user == uu.id_user +left join + stg_seed__guest_services_vat_rates_by_country vat + on uu.billing_country_iso_3 == vat.alpha_3 From bbb9558f62891bc3bafe6005c2eb90e5f0401b32 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Sep 2024 17:22:52 +0200 Subject: [PATCH 04/19] yaml for new version, plus deprecation --- models/intermediate/core/schema.yml | 79 +++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index a877015..bdfbc8d 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -819,12 +819,16 @@ models: date before a starting date. - name: int_core__verification_payments + latest_version: 1 description: >- A simplified table that holds guest journey payments with details around when they happen, what service was being paid, what was the related verification request, etc. Currency rates are converted to GBP with our simple exchange rates view. + + Guest taxes get calculated here. You can find out more about Guest Tax + calculation here: https://www.notion.so/knowyourguest-superhog/Guest-Services-Taxes-How-to-calculate-a5ab4c049d61427fafab669dbbffb3a2?pvs=4 columns: - name: id_verification_to_payment data_type: bigint @@ -884,14 +888,14 @@ models: data_type: bigint - name: verification_payment_type data_type: character varying - - name: amount_in_txn_currency - data_type: numeric - tests: - - not_null - name: currency data_type: character varying tests: - not_null + - name: amount_in_txn_currency + data_type: numeric + tests: + - not_null - name: amount_in_gbp data_type: numeric tests: @@ -900,7 +904,74 @@ models: data_type: character varying - name: notes data_type: character varying + versions: + - v: 1 + deprecation_date: 2024-10-06 00:00:00.00+00:00 + - v: 2 + columns: + - name: total_amount_in_txn_currency + data_type: numeric + description: | + The total amount due created by the interaction, in the currency + of the transaction. + + Should we refund the payment, this is also the amount we will give + back to the guest. + tests: + - not_null + - name: total_amount_in_gbp + data_type: numeric + description: | + The total amount due created by the interaction, in GBP. + + Should we refund the payment, this is also the amount we will give + back to the guest. + tests: + - not_null + - name: tax_amount_in_txn_currency + data_type: numeric + description: | + The tax amount applicable to this transaction, in the currency of + the transaction. + + If the transaction accrues no taxes, will be 0. + tests: + - not_null + - name: tax_amount_in_gbp + data_type: numeric + description: | + The tax amount applicable to this transaction, in GBP. + + If the transaction accrues no taxes, will be 0. + tests: + - not_null + - name: amount_without_taxes_in_txn_currency + data_type: numeric + description: | + The total amount minus taxes, in the currency of the transaction. + + This is what should be considered net-of-taxes revenue for + Superhog. + + If the transaction accrues no taxes, will be equal to the field + total_amount_in_txn_currency. + tests: + - not_null + - name: amount_without_taxes_in_gbp + data_type: numeric + description: | + The total amount minus taxes, in GBP. + + This is what should be considered net-of-taxes revenue for + Superhog. + + If the transaction accrues no taxes, will be equal to the field + total_amount_in_txn_currency. + tests: + - not_null + - include: all + exclude: [amount_in_txn_currency, amount_in_gbp] - name: int_core__country description: | This model contains information regarding countries, such as codes, From 4efc1ba50f351620e84e649c11e69ba77cca9a6a Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Sep 2024 17:27:56 +0200 Subject: [PATCH 05/19] v1 goes back to original state --- .../core/int_core__verification_payments.sql | 44 +------------------ 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments.sql b/models/intermediate/core/int_core__verification_payments.sql index 5afd344..617cec6 100644 --- a/models/intermediate/core/int_core__verification_payments.sql +++ b/models/intermediate/core/int_core__verification_payments.sql @@ -12,11 +12,7 @@ with ), stg_core__payment as (select * from {{ ref("stg_core__payment") }}), stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}), - int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}), - int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), - stg_seed__guest_services_vat_rates_by_country as ( - select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }} - ) + int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}) select vtp.id_verification_to_payment, vtp.id_payment, @@ -36,46 +32,14 @@ select -- Host User identifier is included to speed up -- KPIs execution, even though the host itself -- has nothing to do with the guest payments. - -- --------------------------------------------- - -- Pablo here, I promise I'll find a way to improve performance and get rid - -- of this uglyness. Oh god, it hurts. vr.id_user_host, vtp.id_guest_user, vtp.id_verification, v.id_verification_request, vpt.verification_payment_type, - p.currency, p.amount as amount_in_txn_currency, + p.currency, (p.amount * r.rate) as amount_in_gbp, - p.amount as payment_amount_in_txn_currency, - (p.amount * r.rate) as payment_amount_in_gbp, - p.amount as total_amount_in_txn_currency, - (p.amount * r.rate) as total_amount_in_in_gbp, - /* - Helping comment for logic below. - Given that guest payments are tax inclusive, the tax (column - tax_amount_in_txn_currency) is calculated as: - paid by guest - tax = paid by guest - ( ------------- ) - 1 + VAT Rate - - The amount without tax (column amount_without_taxes_in_txn_currency) gets - calculated as: - paid by guest - amount without tax = ( ------------- ) - 1 + VAT Rate - */ - (p.amount - (p.amount / (1 + vat.vat_rates))) as tax_amount_in_txn_currency, - (p.amount - (p.amount / (1 + vat.vat_rates))) * r.rate as tax_amount_in_gbp, - (p.amount / (1 + vat.vat_rates)) as amount_without_taxes_in_txn_currency, - (p.amount / (1 + vat.vat_rates)) * r.rate as amount_without_taxes_in_gbp, - vat.vat_rate as applicable_vat_tax_rate, - case - when vat.vat_rate = 0 - then false - when vat.vat_rate < 1 and vat.vat_rate > 0 - then true - end as is_vat_taxed, ps.payment_status, p.notes from stg_core__verification_to_payment vtp @@ -93,7 +57,3 @@ left join left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request -left join int_core__unified_user uu on vtp.id_guest_user == uu.id_user -left join - stg_seed__guest_services_vat_rates_by_country vat - on uu.billing_country_iso_3 == vat.alpha_3 From d4b797c741237f0ac506ff550384dd1c9d78c00d Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 6 Sep 2024 17:31:54 +0200 Subject: [PATCH 06/19] add alias --- models/intermediate/core/schema.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index bdfbc8d..af9a848 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -906,6 +906,8 @@ models: data_type: character varying versions: - v: 1 + config: + alias: int_core__verification_payments deprecation_date: 2024-10-06 00:00:00.00+00:00 - v: 2 From 1974da99f7e8a91a95519f30e3fe0a2cff744e22 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 12:48:40 +0200 Subject: [PATCH 07/19] fix typos --- .../core/int_core__verification_payments_v2.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 09d78aa..4aec8b4 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -61,10 +61,10 @@ select amount without tax = ( ------------- ) 1 + VAT Rate */ - (p.amount - (p.amount / (1 + vat.vat_rates))) as tax_amount_in_txn_currency, - (p.amount - (p.amount / (1 + vat.vat_rates))) * r.rate as tax_amount_in_gbp, - (p.amount / (1 + vat.vat_rates)) as amount_without_taxes_in_txn_currency, - (p.amount / (1 + vat.vat_rates)) * r.rate as amount_without_taxes_in_gbp, + (p.amount - (p.amount / (1 + vat.vat_rate))) as tax_amount_in_txn_currency, + (p.amount - (p.amount / (1 + vat.vat_rate))) * r.rate as tax_amount_in_gbp, + (p.amount / (1 + vat.vat_rate)) as amount_without_taxes_in_txn_currency, + (p.amount / (1 + vat.vat_rate)) * r.rate as amount_without_taxes_in_gbp, vat.vat_rate as applicable_vat_tax_rate, case when vat.vat_rate = 0 @@ -89,7 +89,7 @@ left join left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request -left join int_core__unified_user uu on vtp.id_guest_user == uu.id_user +left join int_core__unified_user uu on vtp.id_guest_user = uu.id_user left join stg_seed__guest_services_vat_rates_by_country vat - on uu.billing_country_iso_3 == vat.alpha_3 + on uu.billing_country_iso_3 = vat.alpha_3 From 2cd115eedea95fd185fdf7be87846c6475633c2c Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 12:49:01 +0200 Subject: [PATCH 08/19] remove unnecessary alias, remove unrelated errors in yaml --- models/intermediate/core/schema.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index af9a848..55f10f6 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -906,9 +906,7 @@ models: data_type: character varying versions: - v: 1 - config: - alias: int_core__verification_payments - deprecation_date: 2024-10-06 00:00:00.00+00:00 + deprecation_date: 2024-10-15 00:00:00.00+00:00 - v: 2 columns: From f58e97a3f2746ee5a5c7bceaac367a72ad2c4fcb Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 12:49:32 +0200 Subject: [PATCH 09/19] set references for v1 --- ...int_core__guest_satisfaction_responses.sql | 2 +- ..._monthly_guest_journey_history_by_deal.sql | 2 +- ...monthly_guest_payments_history_by_deal.sql | 2 +- .../int_core__mtd_guest_journey_metrics.sql | 77 ++++++++++++------- .../int_core__mtd_guest_payments_metrics.sql | 9 ++- .../core/int_core__vr_check_in_cover.sql | 2 +- .../core/core__verification_payments.sql | 2 +- 7 files changed, 60 insertions(+), 36 deletions(-) diff --git a/models/intermediate/core/int_core__guest_satisfaction_responses.sql b/models/intermediate/core/int_core__guest_satisfaction_responses.sql index eb4eb49..64c53a7 100644 --- a/models/intermediate/core/int_core__guest_satisfaction_responses.sql +++ b/models/intermediate/core/int_core__guest_satisfaction_responses.sql @@ -1,6 +1,6 @@ with int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments") }} + select * from {{ ref("int_core__verification_payments", version=1) }} ), stg_core__guest_satisfaction_responses as ( select * from {{ ref("stg_core__guest_satisfaction_responses") }} diff --git a/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql b/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql index 75023ea..d369335 100644 --- a/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql +++ b/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql @@ -9,7 +9,7 @@ with select * from {{ ref("int_core__verification_requests") }} ), int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments") }} + select * from {{ ref("int_core__verification_payments", version=1) }} ), int_dates_by_deal as (select * from {{ ref("int_dates_by_deal") }}), int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), diff --git a/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql b/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql index 8a4d27c..a51df88 100644 --- a/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql +++ b/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql @@ -13,7 +13,7 @@ with select * from {{ ref("int_core__verification_requests") }} ), int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments") }} + select * from {{ ref("int_core__verification_payments", version=1) }} ), int_dates_by_deal as (select * from {{ ref("int_dates_by_deal") }}), int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), diff --git a/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql b/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql index 5bfb0a5..03cc29f 100644 --- a/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql +++ b/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql @@ -2,7 +2,6 @@ This model provides Month-To-Date (MTD) based on Guest Journey metrics. */ - {% set dimensions = get_kpi_dimensions() %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} @@ -12,14 +11,16 @@ with select * from {{ ref("int_core__verification_requests") }} ), int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments") }} + select * from {{ ref("int_core__verification_payments", version=1) }} ), int_core__user_host as (select * from {{ ref("int_core__user_host") }}), int_core__mtd_accommodation_segmentation as ( select * from {{ ref("int_core__mtd_accommodation_segmentation") }} ), int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}), - int_dates_mtd_by_dimension as (select * from {{ ref("int_dates_mtd_by_dimension") }}), + int_dates_mtd_by_dimension as ( + select * from {{ ref("int_dates_mtd_by_dimension") }} + ), first_payment_per_verification_request as ( select @@ -46,11 +47,13 @@ with and extract(day from vr.created_date_utc) <= d.day {% if dimension.dimension == "'by_number_of_listings'" %} inner join int_core__user_host u on vr.id_user_host = u.id_user_host - inner join int_core__mtd_accommodation_segmentation mas + inner join + int_core__mtd_accommodation_segmentation mas on u.id_deal = mas.id_deal and d.date = mas.date {% elif dimension.dimension == "'by_billing_country'" %} - inner join int_core__user_host u + inner join + int_core__user_host u on vr.id_user_host = u.id_user_host and u.main_billing_country_iso_3_per_deal is not null {% endif %} @@ -71,15 +74,19 @@ with from int_dates_mtd d inner join int_core__verification_requests vr - on date_trunc('month', vr.verification_estimated_started_date_utc)::date = d.first_day_month - and extract(day from vr.verification_estimated_started_date_utc) <= d.day + on date_trunc('month', vr.verification_estimated_started_date_utc)::date + = d.first_day_month + and extract(day from vr.verification_estimated_started_date_utc) + <= d.day {% if dimension.dimension == "'by_number_of_listings'" %} inner join int_core__user_host u on vr.id_user_host = u.id_user_host - inner join int_core__mtd_accommodation_segmentation mas + inner join + int_core__mtd_accommodation_segmentation mas on u.id_deal = mas.id_deal and d.date = mas.date {% elif dimension.dimension == "'by_billing_country'" %} - inner join int_core__user_host u + inner join + int_core__user_host u on vr.id_user_host = u.id_user_host and u.main_billing_country_iso_3_per_deal is not null {% endif %} @@ -100,15 +107,21 @@ with from int_dates_mtd d inner join int_core__verification_requests vr - on date_trunc('month', vr.verification_estimated_completed_date_utc)::date = d.first_day_month - and extract(day from vr.verification_estimated_completed_date_utc) <= d.day + on date_trunc( + 'month', vr.verification_estimated_completed_date_utc + )::date + = d.first_day_month + and extract(day from vr.verification_estimated_completed_date_utc) + <= d.day {% if dimension.dimension == "'by_number_of_listings'" %} inner join int_core__user_host u on vr.id_user_host = u.id_user_host - inner join int_core__mtd_accommodation_segmentation mas + inner join + int_core__mtd_accommodation_segmentation mas on u.id_deal = mas.id_deal and d.date = mas.date {% elif dimension.dimension == "'by_billing_country'" %} - inner join int_core__user_host u + inner join + int_core__user_host u on vr.id_user_host = u.id_user_host and u.main_billing_country_iso_3_per_deal is not null {% endif %} @@ -129,17 +142,24 @@ with from int_dates_mtd d inner join first_payment_per_verification_request p - on date_trunc('month', p.first_payment_paid_date_utc)::date = d.first_day_month + on date_trunc('month', p.first_payment_paid_date_utc)::date + = d.first_day_month and extract(day from p.first_payment_paid_date_utc) <= d.day {% if dimension.dimension == "'by_number_of_listings'" %} - inner join int_core__verification_requests vr on vr.id_verification_request = p.id_verification_request + inner join + int_core__verification_requests vr + on vr.id_verification_request = p.id_verification_request inner join int_core__user_host u on vr.id_user_host = u.id_user_host - inner join int_core__mtd_accommodation_segmentation mas + inner join + int_core__mtd_accommodation_segmentation mas on u.id_deal = mas.id_deal and d.date = mas.date {% elif dimension.dimension == "'by_billing_country'" %} - inner join int_core__verification_requests vr on vr.id_verification_request = p.id_verification_request - inner join int_core__user_host u + inner join + int_core__verification_requests vr + on vr.id_verification_request = p.id_verification_request + inner join + int_core__user_host u on vr.id_user_host = u.id_user_host and u.main_billing_country_iso_3_per_deal is not null {% endif %} @@ -173,22 +193,23 @@ select cast(pym.paid_guest_journeys as decimal) / coym.completed_guest_journeys as payment_rate_guest_journey from int_dates_mtd_by_dimension d -left join - created_year_month cym +left join + created_year_month cym on cym.date = d.date - and cym.dimension = d.dimension + and cym.dimension = d.dimension and cym.dimension_value = d.dimension_value -left join - started_year_month sym +left join + started_year_month sym on d.date = sym.date - and d.dimension = sym.dimension + and d.dimension = sym.dimension and d.dimension_value = sym.dimension_value -left join +left join completed_year_month coym on d.date = coym.date - and d.dimension = coym.dimension + and d.dimension = coym.dimension and d.dimension_value = coym.dimension_value -left join paid_year_month pym +left join + paid_year_month pym on d.date = pym.date - and d.dimension = pym.dimension + and d.dimension = pym.dimension and d.dimension_value = pym.dimension_value diff --git a/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql b/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql index 5bece0d..e075ab2 100644 --- a/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql +++ b/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql @@ -11,7 +11,7 @@ This model provides Month-To-Date (MTD) based on Guest Revenue metrics. {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} with int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments") }} + select * from {{ ref("int_core__verification_payments", version=1) }} ), int_core__verification_requests as ( select * from {{ ref("int_core__verification_requests") }} @@ -62,7 +62,8 @@ with from int_dates_mtd d inner join int_core__verification_payments vp - on date_trunc('month', vp.payment_paid_date_utc)::date = d.first_day_month + on date_trunc('month', vp.payment_paid_date_utc)::date + = d.first_day_month and extract(day from vp.payment_paid_date_utc) <= d.day {% if dimension.dimension == "'by_number_of_listings'" %} inner join int_core__user_host u on vp.id_user_host = u.id_user_host @@ -71,7 +72,9 @@ with on u.id_deal = mas.id_deal and d.date = mas.date {% elif dimension.dimension == "'by_billing_country'" %} - inner join int_core__user_host u on vp.id_user_host = u.id_user_host + inner join + int_core__user_host u + on vp.id_user_host = u.id_user_host and u.main_billing_country_iso_3_per_deal is not null {% endif %} where upper(vp.payment_status) = {{ var("paid_payment_state") }} diff --git a/models/intermediate/core/int_core__vr_check_in_cover.sql b/models/intermediate/core/int_core__vr_check_in_cover.sql index a2c0aae..01588e4 100644 --- a/models/intermediate/core/int_core__vr_check_in_cover.sql +++ b/models/intermediate/core/int_core__vr_check_in_cover.sql @@ -18,7 +18,7 @@ with amount_in_gbp, payment_status, payment_paid_date_utc - from {{ ref("int_core__verification_payments") }} + from {{ ref("int_core__verification_payments", version=1) }} where verification_payment_type = 'CheckInCover' -- 5 is check-in cover and payment_status in ('Paid', 'Refunded') diff --git a/models/reporting/core/core__verification_payments.sql b/models/reporting/core/core__verification_payments.sql index 5297fa0..afd5715 100644 --- a/models/reporting/core/core__verification_payments.sql +++ b/models/reporting/core/core__verification_payments.sql @@ -1,6 +1,6 @@ with int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments") }} + select * from {{ ref("int_core__verification_payments", version=1) }} ) select vp.id_verification_to_payment as id_verification_to_payment, From 6136db840326f5be41f855f4ef236a89f15debce Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 16:23:02 +0200 Subject: [PATCH 10/19] cte for pre-defining if vat is applicable or not --- .../int_core__verification_payments_v2.sql | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 4aec8b4..6bd2a5f 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -16,6 +16,35 @@ with int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), stg_seed__guest_services_vat_rates_by_country as ( select * from {{ ref("stg_seed__guest_services_vat_rates_by_country") }} + ), + vat_details as ( + select + vtp.id_verification_to_payment, + vat.vat_rate, + case + when vpt.verification_payment_type in ('Waiver', 'Fee', 'CheckInCover') + then true + else false + end as is_service_subject_to_vat, + case + when + vpt.verification_payment_type + not in ('Waiver', 'Fee', 'CheckInCover') + then false + when vat.vat_rate = 0 + then false + when vat.vat_rate < 1 and vat.vat_rate > 0 + then true + end as is_vat_taxed + from stg_core__verification_to_payment vtp + left join + stg_core__verification_payment_type vpt + on vtp.id_verification_payment_type = vpt.id_verification_payment_type + left join int_core__unified_user uu on vtp.id_guest_user = uu.id_user + left join + stg_seed__guest_services_vat_rates_by_country vat + on uu.billing_country_iso_3 = vat.alpha_3 + ) select vtp.id_verification_to_payment, @@ -46,7 +75,7 @@ select vpt.verification_payment_type, p.currency, p.amount as total_amount_in_txn_currency, - (p.amount * r.rate) as total_amount_in_in_gbp, + (p.amount * r.rate)::decimal(19, 4) as total_amount_in_in_gbp, /* Helping comment for logic below. Given that guest payments are tax inclusive, the tax (column @@ -61,17 +90,24 @@ select amount without tax = ( ------------- ) 1 + VAT Rate */ - (p.amount - (p.amount / (1 + vat.vat_rate))) as tax_amount_in_txn_currency, - (p.amount - (p.amount / (1 + vat.vat_rate))) * r.rate as tax_amount_in_gbp, - (p.amount / (1 + vat.vat_rate)) as amount_without_taxes_in_txn_currency, - (p.amount / (1 + vat.vat_rate)) * r.rate as amount_without_taxes_in_gbp, - vat.vat_rate as applicable_vat_tax_rate, - case - when vat.vat_rate = 0 - then false - when vat.vat_rate < 1 and vat.vat_rate > 0 - then true - end as is_vat_taxed, + ( + (p.amount - (p.amount / (1 + vat.vat_rate))) + * vat.is_service_subject_to_vat::int + )::decimal(19, 4) as tax_amount_in_txn_currency, + ( + (p.amount - (p.amount / (1 + vat.vat_rate))) + * vat.is_service_subject_to_vat::int + * r.rate + )::decimal(19, 4) as tax_amount_in_gbp, + (p.amount / (1 + vat.vat_rate))::decimal( + 19, 4 + ) as amount_without_taxes_in_txn_currency, + ((p.amount / (1 + vat.vat_rate)) * r.rate)::decimal( + 19, 4 + ) as amount_without_taxes_in_gbp, + vat.vat_rate, + vat.is_service_subject_to_vat, + vat.is_vat_taxed, ps.payment_status, p.notes from stg_core__verification_to_payment vtp @@ -89,7 +125,5 @@ left join left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request -left join int_core__unified_user uu on vtp.id_guest_user = uu.id_user left join - stg_seed__guest_services_vat_rates_by_country vat - on uu.billing_country_iso_3 = vat.alpha_3 + vat_details vat on vat.id_verification_to_payment = vtp.id_verification_to_payment From 8c96b96ee5ae5437efa47bb69aeab3e19e741a3f Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 16:23:41 +0200 Subject: [PATCH 11/19] small comment --- models/intermediate/core/int_core__verification_payments_v2.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 6bd2a5f..6529044 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -92,7 +92,7 @@ select */ ( (p.amount - (p.amount / (1 + vat.vat_rate))) - * vat.is_service_subject_to_vat::int + * vat.is_service_subject_to_vat::int -- Multiplying by this makes amount 0 if not taxable )::decimal(19, 4) as tax_amount_in_txn_currency, ( (p.amount - (p.amount / (1 + vat.vat_rate))) From 15139e00d01f468ce56170199eff9f8bff66dc33 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 17:10:30 +0200 Subject: [PATCH 12/19] percentage test --- macros/tests/is_valid_percentage.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 macros/tests/is_valid_percentage.sql diff --git a/macros/tests/is_valid_percentage.sql b/macros/tests/is_valid_percentage.sql new file mode 100644 index 0000000..4e90ab9 --- /dev/null +++ b/macros/tests/is_valid_percentage.sql @@ -0,0 +1,10 @@ +/* +The opinionated definition of a valid percentage for this macro: +- It is between 0 and 1 (including 0 and 1 as valid values). +*/ +{% test is_valid_percentage(model, column_name) %} + with validation as (select {{ column_name }} as value from {{ model }}) + select * + from validation + where value > 1 or value < -1 +{% endtest %} From 63599d7a9b052474d2d37d3aa3f5752de8b0b931 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 10 Sep 2024 17:10:37 +0200 Subject: [PATCH 13/19] add columns --- models/intermediate/core/schema.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 55f10f6..7a52e18 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -970,6 +970,33 @@ models: total_amount_in_txn_currency. tests: - not_null + - name: vat_rate + data_type: numeric + description: | + The applicable VAT rate to this payment. This is inferred from (1) + which service is the payment related to and (2) what's the billing + country of the guest. + tests: + - not_null + - is_valid_percentage + + - name: is_service_subject_to_vat + data_type: boolean + description: | + Whether the related payment is subject to VAT. For instance, + deposit payments are not. + tests: + - not_null + + - name: is_subject_to_vat + data_type: boolean + description: | + Syntactic suger to indicate if there's any VAT on this payment. + Will be true if so, false if not for any reason (guest country has + no VAT, the payment is for a deposit, etc.) + tests: + - not_null + - include: all exclude: [amount_in_txn_currency, amount_in_gbp] - name: int_core__country From da3070949a98a1d4b5fdede8f7ac2453ae2f52f7 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Thu, 12 Sep 2024 14:37:45 +0200 Subject: [PATCH 14/19] finish columns and schema --- .../int_core__verification_payments_v2.sql | 34 +++++++++- models/intermediate/core/schema.yml | 68 ++++++++++++++++++- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 6529044..7590a79 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -20,7 +20,7 @@ with vat_details as ( select vtp.id_verification_to_payment, - vat.vat_rate, + coalesce(vat.vat_rate, 0) as vat_rate, case when vpt.verification_payment_type in ('Waiver', 'Fee', 'CheckInCover') then true @@ -35,7 +35,31 @@ with then false when vat.vat_rate < 1 and vat.vat_rate > 0 then true - end as is_vat_taxed + when uu.billing_country_iso_3 is null + then false + else false + end as is_vat_taxed, + (uu.billing_country_iso_3 is null) as is_missing_user_country, + ( + uu.billing_country_iso_3 is not null and vat.alpha_3 is null + ) as is_missing_vat_rate_for_country, + (uu.is_deleted = true) as are_user_details_deleted, + -- This final case isolates null VAT rates that are not caused + -- by the previous columns. The idea is: if any of the previous + -- have happened, that's ok because there are known exceptions. + -- But if the VAT rate is missing and it's not for any of those + -- reasons, we have some unhandled issue. + case + when uu.billing_country_iso_3 is null + then false + when uu.is_deleted = true + then false + when uu.billing_country_iso_3 is not null and vat.alpha_3 is null + then false + when vat.vat_rate is null + then true + else false + end as is_missing_vat_details_without_known_cause from stg_core__verification_to_payment vtp left join stg_core__verification_payment_type vpt @@ -75,7 +99,7 @@ select vpt.verification_payment_type, p.currency, p.amount as total_amount_in_txn_currency, - (p.amount * r.rate)::decimal(19, 4) as total_amount_in_in_gbp, + (p.amount * r.rate)::decimal(19, 4) as total_amount_in_gbp, /* Helping comment for logic below. Given that guest payments are tax inclusive, the tax (column @@ -108,6 +132,10 @@ select vat.vat_rate, vat.is_service_subject_to_vat, vat.is_vat_taxed, + vat.is_missing_user_country, + vat.are_user_details_deleted, + vat.is_missing_vat_rate_for_country, + vat.is_missing_vat_details_without_known_cause, ps.payment_status, p.notes from stg_core__verification_to_payment vtp diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 7a52e18..4fe493b 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -988,15 +988,77 @@ models: tests: - not_null - - name: is_subject_to_vat + - name: is_vat_taxed data_type: boolean description: | Syntactic suger to indicate if there's any VAT on this payment. Will be true if so, false if not for any reason (guest country has no VAT, the payment is for a deposit, etc.) tests: - - not_null - + - not_null + + - name: is_missing_user_country + data_type: boolean + description: | + True if, for some reason, the user doesn't have an informed + country. + + The only known, justified reason for this is that the user was + deleted, along with the billing details. + + If this turns true in any other case, you should really find out + why the guest doesn't have a billing country. + + # should be uncommented once this ticket gets solved: + #tests: + # - not_null + # - accepted_values: + # values: + # - false + # where: are_user_details_deleted != true or are_user_details_deleted is not null + + + + - name: is_missing_vat_rate_for_country + data_type: boolean + description: | + True if the user country is informed, but no VAT rates were found + for it. + + This has to be a joining issue, since our database for VAT rates + covers all the countries in the world. We simply assign a 0% rate + to countries where we don't collect taxes. + + If this turns true in any other case, you should really find out + what's happening. + + # should be uncommented once this ticket gets solved: + #tests: + # - not_null + # - accepted_values: + # values: + # - false + + - name: are_user_details_deleted + data_type: boolean + description: | + True if the user has been deleted, which is a possible explanation + for why there might be no country informed. + + - name: is_missing_vat_details_without_known_cause + data_type: boolean + description: | + True if the VAT rate is missing as a fallback for any + other reason beyond the other one specified in the table. + + If this turns true, you have an unhandled problem and you should + fix it. + + tests: + - not_null + - accepted_values: + values: + - false - include: all exclude: [amount_in_txn_currency, amount_in_gbp] - name: int_core__country From 0312a1ccd8fd227eb13dfc3cbaac7b5a36eb5b4b Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Thu, 12 Sep 2024 15:00:58 +0200 Subject: [PATCH 15/19] remove explicit version reference, rely on latest --- .../core/int_core__guest_satisfaction_responses.sql | 2 +- .../core/int_core__monthly_guest_journey_history_by_deal.sql | 2 +- .../core/int_core__monthly_guest_payments_history_by_deal.sql | 2 +- .../intermediate/core/int_core__mtd_guest_journey_metrics.sql | 2 +- .../intermediate/core/int_core__mtd_guest_payments_metrics.sql | 2 +- models/intermediate/core/int_core__vr_check_in_cover.sql | 2 +- models/reporting/core/core__verification_payments.sql | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/models/intermediate/core/int_core__guest_satisfaction_responses.sql b/models/intermediate/core/int_core__guest_satisfaction_responses.sql index 64c53a7..eb4eb49 100644 --- a/models/intermediate/core/int_core__guest_satisfaction_responses.sql +++ b/models/intermediate/core/int_core__guest_satisfaction_responses.sql @@ -1,6 +1,6 @@ with int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments", version=1) }} + select * from {{ ref("int_core__verification_payments") }} ), stg_core__guest_satisfaction_responses as ( select * from {{ ref("stg_core__guest_satisfaction_responses") }} diff --git a/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql b/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql index d369335..75023ea 100644 --- a/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql +++ b/models/intermediate/core/int_core__monthly_guest_journey_history_by_deal.sql @@ -9,7 +9,7 @@ with select * from {{ ref("int_core__verification_requests") }} ), int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments", version=1) }} + select * from {{ ref("int_core__verification_payments") }} ), int_dates_by_deal as (select * from {{ ref("int_dates_by_deal") }}), int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), diff --git a/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql b/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql index a51df88..8a4d27c 100644 --- a/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql +++ b/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql @@ -13,7 +13,7 @@ with select * from {{ ref("int_core__verification_requests") }} ), int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments", version=1) }} + select * from {{ ref("int_core__verification_payments") }} ), int_dates_by_deal as (select * from {{ ref("int_dates_by_deal") }}), int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), diff --git a/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql b/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql index 03cc29f..ea98536 100644 --- a/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql +++ b/models/intermediate/core/int_core__mtd_guest_journey_metrics.sql @@ -11,7 +11,7 @@ with select * from {{ ref("int_core__verification_requests") }} ), int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments", version=1) }} + select * from {{ ref("int_core__verification_payments") }} ), int_core__user_host as (select * from {{ ref("int_core__user_host") }}), int_core__mtd_accommodation_segmentation as ( diff --git a/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql b/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql index e075ab2..e93a9e0 100644 --- a/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql +++ b/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql @@ -11,7 +11,7 @@ This model provides Month-To-Date (MTD) based on Guest Revenue metrics. {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} with int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments", version=1) }} + select * from {{ ref("int_core__verification_payments") }} ), int_core__verification_requests as ( select * from {{ ref("int_core__verification_requests") }} diff --git a/models/intermediate/core/int_core__vr_check_in_cover.sql b/models/intermediate/core/int_core__vr_check_in_cover.sql index 01588e4..a2c0aae 100644 --- a/models/intermediate/core/int_core__vr_check_in_cover.sql +++ b/models/intermediate/core/int_core__vr_check_in_cover.sql @@ -18,7 +18,7 @@ with amount_in_gbp, payment_status, payment_paid_date_utc - from {{ ref("int_core__verification_payments", version=1) }} + from {{ ref("int_core__verification_payments") }} where verification_payment_type = 'CheckInCover' -- 5 is check-in cover and payment_status in ('Paid', 'Refunded') diff --git a/models/reporting/core/core__verification_payments.sql b/models/reporting/core/core__verification_payments.sql index afd5715..5297fa0 100644 --- a/models/reporting/core/core__verification_payments.sql +++ b/models/reporting/core/core__verification_payments.sql @@ -1,6 +1,6 @@ with int_core__verification_payments as ( - select * from {{ ref("int_core__verification_payments", version=1) }} + select * from {{ ref("int_core__verification_payments") }} ) select vp.id_verification_to_payment as id_verification_to_payment, From ec8490527d070957bd5f859a520749386e73f433 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 13 Sep 2024 13:07:26 +0200 Subject: [PATCH 16/19] reorder case for readability --- .../intermediate/core/int_core__verification_payments_v2.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 7590a79..997aa58 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -33,10 +33,10 @@ with then false when vat.vat_rate = 0 then false - when vat.vat_rate < 1 and vat.vat_rate > 0 - then true when uu.billing_country_iso_3 is null then false + when vat.vat_rate < 1 and vat.vat_rate > 0 + then true else false end as is_vat_taxed, (uu.billing_country_iso_3 is null) as is_missing_user_country, From 092b8bd7255d17d678bb39fc4732e9eb774b7a53 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 13 Sep 2024 13:09:01 +0200 Subject: [PATCH 17/19] clarify refund is not in GBP --- models/intermediate/core/schema.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 4fe493b..29cba6d 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -925,8 +925,9 @@ models: description: | The total amount due created by the interaction, in GBP. - Should we refund the payment, this is also the amount we will give - back to the guest. + Should we refund the payment, this is the GBP equivalent of the + amount we will give back to the guest, but we won't be paying in + GBP unless the original payment was in GBP. tests: - not_null - name: tax_amount_in_txn_currency @@ -991,7 +992,7 @@ models: - name: is_vat_taxed data_type: boolean description: | - Syntactic suger to indicate if there's any VAT on this payment. + Syntactic sugar to indicate if there's any VAT on this payment. Will be true if so, false if not for any reason (guest country has no VAT, the payment is for a deposit, etc.) tests: @@ -1009,16 +1010,14 @@ models: If this turns true in any other case, you should really find out why the guest doesn't have a billing country. - # should be uncommented once this ticket gets solved: + # should be uncommented once this ticket gets solved: #tests: # - not_null # - accepted_values: # values: # - false # where: are_user_details_deleted != true or are_user_details_deleted is not null - - - name: is_missing_vat_rate_for_country data_type: boolean description: | @@ -1032,7 +1031,7 @@ models: If this turns true in any other case, you should really find out what's happening. - # should be uncommented once this ticket gets solved: + # should be uncommented once this ticket gets solved: #tests: # - not_null # - accepted_values: @@ -1044,7 +1043,7 @@ models: description: | True if the user has been deleted, which is a possible explanation for why there might be no country informed. - + - name: is_missing_vat_details_without_known_cause data_type: boolean description: | @@ -1055,7 +1054,7 @@ models: fix it. tests: - - not_null + - not_null - accepted_values: values: - false From 4cf74db49a0e0fd6f0a2ea9b1313cbc0954b959a Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 13 Sep 2024 15:10:58 +0200 Subject: [PATCH 18/19] replace hardcode with variable --- .../core/int_core__verification_payments_v2.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/models/intermediate/core/int_core__verification_payments_v2.sql b/models/intermediate/core/int_core__verification_payments_v2.sql index 997aa58..67406cf 100644 --- a/models/intermediate/core/int_core__verification_payments_v2.sql +++ b/models/intermediate/core/int_core__verification_payments_v2.sql @@ -1,4 +1,7 @@ {{ config(materialized="table") }} + +{% set vat_applicable_services = "('Waiver', 'Fee', 'CheckInCover')" %} + with stg_core__verification_to_payment as ( select * from {{ ref("stg_core__verification_to_payment") }} @@ -22,14 +25,12 @@ with vtp.id_verification_to_payment, coalesce(vat.vat_rate, 0) as vat_rate, case - when vpt.verification_payment_type in ('Waiver', 'Fee', 'CheckInCover') + when vpt.verification_payment_type in {{ vat_applicable_services }} then true else false end as is_service_subject_to_vat, case - when - vpt.verification_payment_type - not in ('Waiver', 'Fee', 'CheckInCover') + when vpt.verification_payment_type not in {{ vat_applicable_services }} then false when vat.vat_rate = 0 then false From 6434c5c88d232cea96c87450be5a97a60620bcc6 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 13 Sep 2024 15:14:32 +0200 Subject: [PATCH 19/19] replace custom generic test with standard range between one --- macros/tests/is_valid_percentage.sql | 10 ---------- models/intermediate/core/schema.yml | 5 ++++- 2 files changed, 4 insertions(+), 11 deletions(-) delete mode 100644 macros/tests/is_valid_percentage.sql diff --git a/macros/tests/is_valid_percentage.sql b/macros/tests/is_valid_percentage.sql deleted file mode 100644 index 4e90ab9..0000000 --- a/macros/tests/is_valid_percentage.sql +++ /dev/null @@ -1,10 +0,0 @@ -/* -The opinionated definition of a valid percentage for this macro: -- It is between 0 and 1 (including 0 and 1 as valid values). -*/ -{% test is_valid_percentage(model, column_name) %} - with validation as (select {{ column_name }} as value from {{ model }}) - select * - from validation - where value > 1 or value < -1 -{% endtest %} diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 29cba6d..9a47223 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -979,7 +979,10 @@ models: country of the guest. tests: - not_null - - is_valid_percentage + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 0.99 # If we ever have a 100% tax rate... Let's riot working please + strictly: false - name: is_service_subject_to_vat data_type: boolean