Final update

This commit is contained in:
Joaquin Ossa 2025-02-26 08:24:50 +01:00
parent cfc6971cb4
commit 465bd51ff2
4 changed files with 18 additions and 26 deletions

View file

@ -125,30 +125,21 @@ with
int_daily_currency_exchange_rates cer_gbp int_daily_currency_exchange_rates cer_gbp
on dri.created_date_utc = cer_gbp.rate_date_utc on dri.created_date_utc = cer_gbp.rate_date_utc
and (cm.corrective_measure ->> 'Currency') = cer_gbp.from_currency and (cm.corrective_measure ->> 'Currency') = cer_gbp.from_currency
and 'GBP' = cer.to_currency and cer.to_currency = 'GBP'
group by dri.id_incident, dri.host_currency group by dri.id_incident, dri.host_currency
), ),
guest_amounts_in_gbp as ( guest_amounts_in_gbp as (
select select
i.id_incident, i.id_incident,
(i.deposit_retained_amount_in_txn_currency * cer_deposit.rate)::decimal( (i.guest_contribution_amount_in_txn_currency * cer.rate)::decimal(
19, 4 19, 4
) as deposit_retained_amount_in_gbp, ) as guest_contribution_amount_in_gbp
(
i.guest_contribution_amount_in_txn_currency * cer_contribution.rate
)::decimal(19, 4) as guest_contribution_amount_in_gbp
from stg_resolutions__incidents i from stg_resolutions__incidents i
left join logs_timeline lt on i.id_incident = lt.id_incident
left join left join
int_daily_currency_exchange_rates cer_deposit int_daily_currency_exchange_rates cer
on (lt.last_status_at_utc)::date = cer_deposit.rate_date_utc on (i.calculation_at_utc)::date = cer.rate_date_utc
and cer_deposit.from_currency = i.deposit_retained_currency and cer.from_currency = i.guest_contribution_currency
and cer_deposit.to_currency = 'GBP' and cer.to_currency = 'GBP'
left join
int_daily_currency_exchange_rates cer_contribution
on (lt.last_status_at_utc)::date = cer_contribution.rate_date_utc
and cer_contribution.from_currency = i.guest_contribution_currency
and cer_contribution.to_currency = 'GBP'
) )
select select
@ -232,7 +223,6 @@ select
i.is_guest_deposit_collected, i.is_guest_deposit_collected,
i.deposit_retained_amount_in_txn_currency, i.deposit_retained_amount_in_txn_currency,
i.deposit_retained_currency, i.deposit_retained_currency,
ga.deposit_retained_amount_in_gbp,
-- Guest Involvements -- Guest Involvements
i.has_guest_contributed_to_cost, i.has_guest_contributed_to_cost,
@ -261,6 +251,6 @@ left join damage_report dr on i.id_incident = dr.id_incident
left join guest_amounts_in_gbp ga on i.id_incident = ga.id_incident left join guest_amounts_in_gbp ga on i.id_incident = ga.id_incident
left join left join
int_daily_currency_exchange_rates cer int_daily_currency_exchange_rates cer
on (lt.last_status_at_utc)::date = cer.rate_date_utc on (i.calculation_at_utc)::date = cer.rate_date_utc
and cer.from_currency = 'USD' and cer.from_currency = 'USD'
and cer.to_currency = 'GBP' and cer.to_currency = 'GBP'

View file

@ -328,14 +328,6 @@ models:
- not_null: - not_null:
where: "deposit_retained_amount_in_txn_currency > 0" where: "deposit_retained_amount_in_txn_currency > 0"
- name: deposit_retained_amount_in_gbp
data_type: numeric
description: "Amount of the deposit retained in GBP."
data_tests:
- dbt_expectations.expect_column_values_to_be_between:
min_value: 0
strictly: false
- name: has_guest_contributed_to_cost - name: has_guest_contributed_to_cost
data_type: boolean data_type: boolean
description: "If the guest has agreed to contribute to the cost description: "If the guest has agreed to contribute to the cost

View file

@ -301,6 +301,13 @@ models:
data_type: text data_type: text
description: "List of items that were damaged." description: "List of items that were damaged."
- name: calculation_at_utc
data_type: timestamp without time zone
description: "Timestamp of the calculation."
data_tests:
- not_null:
where: "calculated_payout_amount_in_txn_currency > 0"
- name: protection_name - name: protection_name
data_type: text data_type: text
description: "Indicates the selected booking protection plan, description: "Indicates the selected booking protection plan,

View file

@ -194,6 +194,9 @@ select
-- Calculator -- Calculator
{{ adapter.quote("documents") }} {{ adapter.quote("documents") }}
-> 'SavedCalculation' -> 'SavedCalculation'
->> 'CalculationDate' as calculation_at_utc,
{{ adapter.quote("documents") }}
-> 'SavedCalculation'
->> 'ProtectionName' as protection_name, ->> 'ProtectionName' as protection_name,
({{ adapter.quote("documents") }} -> 'SavedCalculation' ->> 'WasOverriden')::boolean ({{ adapter.quote("documents") }} -> 'SavedCalculation' ->> 'WasOverriden')::boolean
as was_overriden, as was_overriden,