From 60ebb13f1d9f071929c544767208c8053026095f Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 23 Dec 2024 16:20:12 +0100 Subject: [PATCH] Completed schema --- .../int_screen_and_protect__invoices.sql | 40 ++- .../screen_and_protect/schema.yml | 295 +++++++++++++++++- 2 files changed, 319 insertions(+), 16 deletions(-) diff --git a/models/intermediate/screen_and_protect/int_screen_and_protect__invoices.sql b/models/intermediate/screen_and_protect/int_screen_and_protect__invoices.sql index e62c345..9799706 100644 --- a/models/intermediate/screen_and_protect/int_screen_and_protect__invoices.sql +++ b/models/intermediate/screen_and_protect/int_screen_and_protect__invoices.sql @@ -85,7 +85,10 @@ with from int_screen_and_protect__verification_requests vr where upper(vr.verification_status) = '{{ rejected_status }}' - or vr.is_protected is false + or ( + vr.is_protected is false + and upper(vr.protection_type) <> '{{ damage_waiver }}' + ) ), -- All cancelled bookings, excluding those with damage waiver protection or that -- have been charged the rejected fee @@ -138,9 +141,13 @@ with then bp.long_stay_fee_in_local_currency else bp.short_stay_fee_in_local_currency end as nightly_fee_in_local_currency, - vr.monthly_volume_discount_percentage * ad.is_monthly_volume_discount_active - + vr.monthly_general_discount_percentage - * ad.is_monthly_general_discount_active as discount_percentage, + coalesce( + vr.monthly_volume_discount_percentage + * ad.is_monthly_volume_discount_active + + vr.monthly_general_discount_percentage + * ad.is_monthly_general_discount_active, + 0 + ) as discount_percentage, vr.checkout_date_utc as invoice_date_utc from int_screen_and_protect__verification_requests vr inner join @@ -168,9 +175,13 @@ with then sp.long_stay_fee_in_local_currency else sp.short_stay_fee_in_local_currency end as nightly_fee_in_local_currency, - vr.monthly_volume_discount_percentage * ad.is_monthly_volume_discount_active - + vr.monthly_general_discount_percentage - * ad.is_monthly_general_discount_active as discount_percentage, + coalesce( + vr.monthly_volume_discount_percentage + * ad.is_monthly_volume_discount_active + + vr.monthly_general_discount_percentage + * ad.is_monthly_general_discount_active, + 0 + ) as discount_percentage, vr.checkout_date_utc as invoice_date_utc from int_screen_and_protect__verification_requests vr inner join @@ -200,9 +211,13 @@ with then sp.long_stay_fee_in_local_currency else sp.short_stay_fee_in_local_currency end as nightly_fee_in_local_currency, - vr.monthly_volume_discount_percentage * ad.is_monthly_volume_discount_active - + vr.monthly_general_discount_percentage - * ad.is_monthly_general_discount_active as discount_percentage, + coalesce( + vr.monthly_volume_discount_percentage + * ad.is_monthly_volume_discount_active + + vr.monthly_general_discount_percentage + * ad.is_monthly_general_discount_active, + 0 + ) as discount_percentage, vr.checkout_date_utc as invoice_date_utc from int_screen_and_protect__verification_requests vr inner join @@ -239,6 +254,9 @@ select vr.id_accommodation, vr.is_protected, vr.protection_type, + vr.protection_basic_amount_in_local_currency, + vr.protection_starting_amount_in_local_currency, + vr.protection_extended_amount_in_local_currency, vr.verification_status, vr.id_currency, vr.checkin_date_utc, @@ -258,7 +276,7 @@ select / 100 as discount_amount_in_local_currency, bnf.nightly_fee_in_local_currency * vr.number_of_nights - * (1 - bnf.discount_percentage) + * (100 - bnf.discount_percentage) / 100 as fee_after_discount_in_local_currency, coalesce(bbf.invoice_date_utc, bnf.invoice_date_utc) as invoice_date_utc, vr.user_email, diff --git a/models/intermediate/screen_and_protect/schema.yml b/models/intermediate/screen_and_protect/schema.yml index a608224..a5fb847 100644 --- a/models/intermediate/screen_and_protect/schema.yml +++ b/models/intermediate/screen_and_protect/schema.yml @@ -9,8 +9,8 @@ models: data_tests: - at_least_one_null: columns: - - monthly_volume_discount - - monthly_general_discount + - monthly_volume_discount_percentage + - monthly_general_discount_percentage columns: - name: id_verification data_type: text @@ -215,15 +215,22 @@ models: - name: checkin_date_utc data_type: date - description: Check-in date for the booking. + description: "Check-in date for the booking." + tests: + - not_null - name: checkout_date_utc data_type: date - description: Check-out date for the booking. + description: "Check-out date for the booking." + tests: + - not_null - name: number_of_nights data_type: integer - description: Number of nights for the booking. + description: Number of nights for the reservation. + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 1 - name: is_cancelled data_type: boolean @@ -338,3 +345,281 @@ models: Date of when the verification request was created in Cosmos DB. data_tests: - not_null + + - name: int_screen_and_protect__invoices + description: | + This table contains records of invoices related to verification requests + from the Screen and Protect API. + It tracks financial details such as fees, discounts, and booking-related + metadata. + columns: + - name: id_verification + data_type: text + description: "Unique identifier for the verification request." + tests: + - not_null + - unique + + - name: id_booking + data_type: text + description: "Unique identifier for the booking associated with the verification." + tests: + - not_null + + - name: id_user_partner + data_type: text + description: "Identifier for the partner user initiating the verification." + tests: + - not_null + + - name: id_accommodation + data_type: text + description: "Identifier for the accommodation related to the booking." + + - name: is_protected + data_type: boolean + description: "Indicates if the booking is protected or not." + + - name: protection_type + data_type: text + description: "Specific protection type for the request." + tests: + - not_null + - accepted_values: + values: + - "SCREEN & PROTECT" + - "BASIC PROTECTION" + - "STANDALONE PROTECTION" + - "DAMAGE WAIVER" + - "PET PROTECTION" + + - name: protection_starting_amount_in_local_currency + data_type: numeric + description: Field used for protection type "STANDALONE PROTECTION" to + indicate the starting level of protection. + In local currency. + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 100000 + strictly: true + + - name: protection_basic_amount_in_local_currency + data_type: numeric + description: Field used for protection type "SCREEN & PROTECT", + "BASIC PROTECTION" or "DAMAGE WAIVER" to show the basic amount of protection. + In local currency. + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 100000 + strictly: true + + - name: protection_extended_amount_in_local_currency + data_type: numeric + description: Field used for protection type "SCREEN & PROTECT", + or "STANDALONE PROTECTION" to show the basic amount of protection. + In local currency. + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 50000000 + strictly: true + + - name: pet_protection + data_type: boolean + description: Indicates if pet protection was included. + + - name: verification_status + data_type: text + description: Outcome of the verification process. + tests: + - not_null + - accepted_values: + values: + - "APPROVED" + - "FLAGGED" + - "REJECTED" + + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key to the + currency table" + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + + - name: checkin_date_utc + data_type: date + description: "Check-in date for the booking." + tests: + - not_null + + - name: checkout_date_utc + data_type: date + description: "Check-out date for the booking." + tests: + - not_null + + - name: number_of_nights + data_type: integer + description: Number of nights for the reservation. + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 1 + + - name: is_cancelled + data_type: boolean + description: "Indicates if the booking was canceled." + + - name: cancelled_at_utc + data_type: timestamp without time zone + description: "Timestamp when the booking was canceled." + + - name: cancelled_date_utc + data_type: date + description: "Date when the booking was canceled." + + - name: booking_fee_in_local_currency + data_type: numeric + description: "Fee in local currency associated with the booking." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 10000 + strictly: true + + - name: nightly_fee_in_local_currency + data_type: numeric + description: "Nightly fee in local currency for the booking." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 10000 + strictly: true + + - name: total_fee_in_local_currency + data_type: numeric + description: "Total fee in local currency, inclusive of all charges." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 10000000 + strictly: true + + - name: discount_percentage + data_type: numeric + description: "Percentage of discount applied to the booking." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 99 + strictly: false + + - name: discount_amount_in_local_currency + data_type: numeric + description: "Amount of discount in local currency applied to the booking." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 10000000 + strictly: false + + - name: fee_after_discount_in_local_currency + data_type: numeric + description: "Total fee in local currency after applying the discount." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 10000000 + strictly: true + + - name: invoice_date_utc + data_type: date + description: "Date to consider for the invoice." + tests: + - not_null + + - name: user_email + data_type: text + description: "Email address of the user associated with the booking." + + - name: company_name + data_type: text + description: "Name of the company associated with the booking." + + - name: property_manager_name + data_type: text + description: "Name of the property manager." + + - name: property_manager_email + data_type: text + description: "Email address of the property manager." + + - name: listing_name + data_type: text + description: "Name of the listing." + + - name: listing_address + data_type: text + description: "Address of the listing." + + - name: listing_town + data_type: text + description: "Town where the listing is located." + + - name: listing_country + data_type: text + description: "Country code where the listing is located." + + - name: listing_postcode + data_type: text + description: "Postcode of the listing." + + - name: pets_allowed + data_type: boolean + description: "Indicates if pets are allowed at the listing." + + - name: status_updated_at_utc + data_type: timestamp without time zone + description: "Timestamp of the last status update for the verification." + tests: + - not_null + + - name: status_updated_date_utc + data_type: date + description: "Date of the last status update for the verification." + tests: + - not_null + + - name: updated_at_utc + data_type: timestamp without time zone + description: "Timestamp of the last update to the record." + tests: + - not_null + + - name: updated_date_utc + data_type: date + description: "Date of the last update to the record." + tests: + - not_null + + - name: creation_at_utc + data_type: timestamp without time zone + description: "Timestamp of when the reservation was created." + tests: + - not_null + + - name: creation_date_utc + data_type: date + description: "Date of when the reservation was created." + tests: + - not_null + + - name: cosmos_created_date_utc + data_type: date + description: "Date of when the verification request was created in Cosmos DB." + tests: + - not_null