Merged PR 5366: Adds Incident data to Booking Summary
# Description This PR moves the categorisation of Bookings with Incidents from the flagging specific model to Booking Summary, effectively keeping this at Booking ID level. This also handles the direct dependency with the flagging categorisation model. I also improved the documentation and test coverage on the Booking Summary as it's becoming more and more central to many areas. # 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: #30676
This commit is contained in:
parent
92b144d78e
commit
affeac612a
3 changed files with 453 additions and 258 deletions
|
|
@ -1,71 +1,17 @@
|
|||
{% set risk_booking_status = ("NOTAPPROVED", "FLAGGED") %}
|
||||
{% set no_risk_booking_status = ("APPROVED", "NOFLAGS") %}
|
||||
{% set incident_duplicated_status = "CLOSED - DUPLICATE" %}
|
||||
{% set incident_finished_status = (
|
||||
"RESOLVED",
|
||||
"RESOLVED EXCEPTION",
|
||||
"CLOSED - NO REPLY",
|
||||
"CLOSED - OTHER",
|
||||
"CLOSED - WAIVER CR",
|
||||
"CLOSED - LATE REPORT",
|
||||
"CLOSED - NOT COVERED",
|
||||
"CLOSED - NOT LIABLE",
|
||||
"CLOSED HOST REQUEST",
|
||||
"CLOSED - NOT APPROVED",
|
||||
"CLOSED - THIRD PARTY",
|
||||
) %}
|
||||
{% set days_from_checkout_to_completion = 14 %}
|
||||
|
||||
{{ config(materialized="table") }}
|
||||
with
|
||||
int_booking_summary as (select * from {{ ref("int_booking_summary") }}),
|
||||
int_resolutions__incidents as (
|
||||
select * from {{ ref("int_resolutions__incidents") }}
|
||||
),
|
||||
-- The same booking can have multiple Incidents
|
||||
deduplicated_incidents as (
|
||||
select
|
||||
id_booking,
|
||||
sum(submitted_payout_amount_in_gbp) as submitted_payout_amount_in_gbp,
|
||||
case
|
||||
when sum(submitted_payout_amount_in_gbp) > 0 then true else false
|
||||
end as has_submitted_payout,
|
||||
case
|
||||
when
|
||||
sum(
|
||||
case
|
||||
when
|
||||
upper(current_status_name)
|
||||
in {{ incident_finished_status }}
|
||||
then 1
|
||||
else 0
|
||||
end
|
||||
)
|
||||
> 0
|
||||
then true
|
||||
else false
|
||||
end as is_incident_finished
|
||||
from int_resolutions__incidents
|
||||
where upper(current_status_name) != '{{ incident_duplicated_status }}'
|
||||
group by 1
|
||||
),
|
||||
new_dash_protected_bookings as (
|
||||
select
|
||||
id_booking,
|
||||
case
|
||||
when
|
||||
(current_date - booking_check_out_date_utc)
|
||||
> {{ days_from_checkout_to_completion }}
|
||||
then true
|
||||
else false
|
||||
end as is_booking_completed,
|
||||
case
|
||||
when upper(booking_status) in {{ risk_booking_status }}
|
||||
then true
|
||||
when upper(booking_status) in {{ no_risk_booking_status }}
|
||||
then false
|
||||
else null
|
||||
end as is_booking_flagged_as_risk
|
||||
is_booking_past_completion_date as is_booking_completed,
|
||||
is_booking_flagged_as_risk,
|
||||
has_resolution_incident as has_claim,
|
||||
has_resolution_submitted_payout as has_submitted_payout,
|
||||
has_resolution_incident_finished as is_incident_finished,
|
||||
coalesce(
|
||||
resolution_submitted_payout_amount_in_gbp, 0
|
||||
) as submitted_payout_amount_in_gbp
|
||||
from int_booking_summary
|
||||
where
|
||||
-- Bookings from New Dash users with Id Deal
|
||||
|
|
@ -76,25 +22,9 @@ with
|
|||
has_protection_service_business_type
|
||||
or has_deposit_management_service_business_type
|
||||
)
|
||||
-- Bookings with relevant status (i.e. not cancelled, not pending)
|
||||
and (
|
||||
upper(booking_status) in {{ risk_booking_status }}
|
||||
or upper(booking_status) in {{ no_risk_booking_status }}
|
||||
)
|
||||
),
|
||||
bookings_with_incidents as (
|
||||
select
|
||||
ndpb.id_booking,
|
||||
ndpb.is_booking_completed,
|
||||
ndpb.is_booking_flagged_as_risk,
|
||||
case when di.id_booking is not null then true else false end as has_claim,
|
||||
coalesce(di.has_submitted_payout, false) as has_submitted_payout,
|
||||
coalesce(di.is_incident_finished, false) as is_incident_finished,
|
||||
coalesce(
|
||||
submitted_payout_amount_in_gbp, 0
|
||||
) as submitted_payout_amount_in_gbp
|
||||
from new_dash_protected_bookings ndpb
|
||||
left join deduplicated_incidents di on ndpb.id_booking = di.id_booking
|
||||
-- Bookings with flagging categorisation (this excludes
|
||||
-- Cancelled/Incomplete Information/Rejected bookings)
|
||||
and is_booking_flagged_as_risk is not null
|
||||
)
|
||||
select
|
||||
-- High Level Bookings --
|
||||
|
|
@ -275,4 +205,4 @@ select
|
|||
and is_incident_finished
|
||||
) as completed_no_risk_with_submitted_payout_amount_paid_in_gbp
|
||||
|
||||
from bookings_with_incidents
|
||||
from new_dash_protected_bookings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue