Merged PR 4423: Logic for Billable Bookings in New Dash Bookings

# Description

Changes:
* Tags services to be billed (invoiced to host) in the staging models of product_service and protection_plan
* Propagates into booking_service_detail master table. This also computes billable dates.
* Propagates into booking_summary master table. This has the final determination of a booking being billable or not, and when the first and last billing should occur.

# 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: #27619
This commit is contained in:
Oriol Roqué Paniagua 2025-02-17 15:01:44 +00:00
parent 399feba9af
commit a3793121af
6 changed files with 160 additions and 6 deletions

View file

@ -3902,17 +3902,39 @@ models:
data_type: date
description: |
Identifies the first date in which the billing item for this service
is supposed to be charged. It can be null if no billing item is
available. If there's only one billing item, this field will contain
is supposed to be charged or when the guest payment happens.
It can be null if no service supposed to be charged is available.
If there's only one chargeable service, this field will contain
the same value as service_last_chargeable_date_utc.
- name: service_last_chargeable_date_utc
data_type: date
description: |
Identifies the last date in which the billing item for this service
is supposed to be charged or when the guest payment happens.
It can be null if no service supposed to be charged is available.
If there's only one chargeable service, this field will contain
the same value as service_first_chargeable_date_utc.
- name: service_first_billable_date_utc
data_type: date
description: |
Identifies the first date in which the billing item for this service
is supposed to be charged. It can be null if no billing item is
available. If there's only one billing item, this field will contain
the same value as service_first_chargeable_date_utc.
the same value as service_last_billable_date_utc.
It's similar to Chargeable Services logic but it only considers
Billable Services to the Host (excluding Guest Payments and free services).
- name: service_last_billable_date_utc
data_type: date
description: |
Identifies the last date in which the billing item for this service
is supposed to be charged. It can be null if no billing item is
available. If there's only one billing item, this field will contain
the same value as service_first_billable_date_utc.
It's similar to Chargeable Services logic but it only considers
Billable Services to the Host (excluding Guest Payments and free services).
- name: is_missing_currency_code
data_type: boolean
@ -3946,6 +3968,15 @@ models:
data_tests:
- not_null
- name: is_billable_service
data_type: boolean
description: |
Flag that determines if the service is billable or not.
If the service is billable, it is supposed to be included in the
invoice to the host.
data_tests:
- not_null
- name: is_missing_chargeable_date
data_type: boolean
description: |
@ -4170,6 +4201,22 @@ models:
Identifies the last moment in time in which the last
service applied to this booking is supposed to be charged.
- name: service_first_billable_date_utc
data_type: date
description: |
Identifies the first moment in time in which the first
service applied to this booking is supposed to be billed.
This excludes Guest Payments, and only includes services to
be invoiced to the Host.
- name: service_last_billable_date_utc
data_type: date
description: |
Identifies the last moment in time in which the last
service applied to this booking is supposed to be billed.
This excludes Guest Payments, and only includes services to
be invoiced to the Host.
- name: service_first_created_at_utc
data_type: timestamp
description: |
@ -4211,6 +4258,12 @@ models:
Total number of Services different from Basic Screening
applied to this Booking.
- name: number_of_applied_billable_services
data_type: integer
description: |
Total number of Services that require an invoice to the Host
to the Host, that are applied to this Booking.
- name: is_booking_chargeable
data_type: boolean
description: |
@ -4226,6 +4279,25 @@ models:
data_tests:
- not_null
- name: is_booking_billable
data_type: boolean
description: |
Flag to identify it the Booking is billable or not.
In essence, it solves the question: are we supposed to invoice
a certain amount to the host to get money out of this booking, or not?
To be considered as billable, a billable date needs to exist
as well as the total price of billable services, converted to GBP,
need to be strictly greater than 0.
The fact that a booking is not billable does not necessarily mean that
it won't be in the future.
The fact that a booking is not billable does not necessarily mean that
it's not chargeable, since Guest Payments could still apply.
Similarly, if the booking is billable it does not necessarily mean that
is actually billed.
It cannot be null.
data_tests:
- not_null
- name: is_missing_currency_code_in_service_detail
data_type: boolean
description: |
@ -4248,6 +4320,11 @@ models:
Flag to identify if the booking has any service different from
Basic Screening or not.
- name: has_billable_services
data_type: boolean
description: |
Flag to identify if the booking has any billable service or not.
- name: has_screening_service_business_type
data_type: boolean
description: |