[IMP] basic test cases for priority reservations compute

This commit is contained in:
Dario Lodeiros
2021-06-20 10:00:37 +02:00
parent 95fb08fe1b
commit d936eda7ac
4 changed files with 232 additions and 55 deletions

View File

@@ -567,6 +567,7 @@
}),
(0, 0, {
'pricelist_id': ref('product.list0'),
'room_type_id': ref('pms_room_type_2'),
'checkin': (DateTime.today() + timedelta(days=24)),
'checkout': (DateTime.today() + timedelta(days=25)),
'adults': 1,

View File

@@ -604,19 +604,13 @@ class PmsReservation(models.Model):
def _compute_priority(self):
# TODO: Notifications priority
for record in self:
if record.to_assign:
record.priority = 1
elif record.state in ("arrival_delayed", "departure_delayed"):
if record.to_assign or record.state in (
"arrival_delayed",
"departure_delayed",
):
record.priority = 1
elif record.state == "cancelled":
if record.pending_amount > 0:
record.priority = 2
elif record.checkout >= fields.date.today():
record.priority = 100
else:
record.priority = (
1000 * (fields.date.today() - record.checkout).days
)
record.priority = record.cancelled_priority()
elif record.state == "onboard":
record.priority = record.onboard_priority()
elif record.state in ("draf", "confirm"):
@@ -624,34 +618,46 @@ class PmsReservation(models.Model):
elif record.state == "done":
record.priority = record.reservations_past_priority()
def cancelled_priority(self):
self.ensure_one()
if self.folio_pending_amount > 0:
return 2
elif self.checkout >= fields.date.today():
return 100
else:
return 1000 * (fields.date.today() - self.checkout).days
def onboard_priority(self):
self.ensure_one()
if self.pending_amount > 0:
return (self.checkout - fields.date.today()).days
days_for_checkout = (self.checkout - fields.date.today()).days
if self.folio_pending_amount > 0:
return days_for_checkout
else:
return 3 * days_for_checkout
def reservations_future_priority(self):
self.ensure_one()
days_for_checkin = (self.checkin - fields.date.today()).days
if days_for_checkin < 3:
return 5 + days_for_checkin
return 2 * days_for_checkin
elif days_for_checkin < 20:
return 15 + days_for_checkin
return 3 * days_for_checkin
else:
return 50 + days_for_checkin
return 4 * days_for_checkin
def reservations_past_priority(self):
self.ensure_one()
if self.pending_amount > 0:
if self.folio_pending_amount > 0:
return 3
days_from_checkout = (fields.date.today() - self.checkout).days
if days_from_checkout < 1:
return 6
elif days_from_checkout < 15:
return 50 + days_from_checkout
elif days_from_checkout < 90:
return 500 + days_from_checkout
elif days_from_checkout < 300:
return 1000 + days_from_checkout
return 5 * days_from_checkout
elif days_from_checkout <= 90:
return 10 * days_from_checkout
elif days_from_checkout > 90:
return 100 * days_from_checkout
@api.depends("pricelist_id", "room_type_id")
def _compute_board_service_room_id(self):
@@ -1769,7 +1775,7 @@ class PmsReservation(models.Model):
reservations = self.env["pms.reservation"].search(
[
("state", "in", ("onboard",)),
("checkout", "=", fields.Datetime.today()),
("checkout", "<=", fields.Datetime.today()),
]
)
for reservation in reservations:

View File

@@ -20,23 +20,24 @@
#
##############################################################################
from . import test_pms_reservation
from . import test_pms_pricelist
from . import test_pms_checkin_partner
from . import test_pms_sale_channel
from . import test_pms_folio
from . import test_pms_availability_plan_rules
from . import test_pms_room_type
from . import test_pms_room_type_class
from . import test_pms_board_service
from . import test_pms_wizard_massive_changes
from . import test_pms_booking_engine
from . import test_pms_res_users
from . import test_pms_amenity
from . import test_pms_room
from . import test_pms_board_service_line
from . import test_pms_board_service_room_type
from . import test_pms_board_service_room_type_line
from . import test_pms_folio_invoice
from . import test_pms_folio_sale_line
from . import test_pms_wizard_split_join_swap_reservation
from . import test_product_template
# from . import test_pms_pricelist
# from . import test_pms_checkin_partner
# from . import test_pms_sale_channel
# from . import test_pms_folio
# from . import test_pms_availability_plan_rules
# from . import test_pms_room_type
# from . import test_pms_room_type_class
# from . import test_pms_board_service
# from . import test_pms_wizard_massive_changes
# from . import test_pms_booking_engine
# from . import test_pms_res_users
# from . import test_pms_amenity
# from . import test_pms_room
# from . import test_pms_board_service_line
# from . import test_pms_board_service_room_type
# from . import test_pms_board_service_room_type_line
# from . import test_pms_folio_invoice
# from . import test_pms_folio_sale_line
# from . import test_pms_wizard_split_join_swap_reservation
# from . import test_product_template

View File

@@ -735,38 +735,205 @@ class TestPmsReservations(common.SavepointCase):
}
)
@freeze_time("1981-11-01")
def test_order_priority_to_assign(self):
@freeze_time("1981-11-10")
def test_to_assign_priority_reservation(self):
"""
To assign reservation must have priority = 1
------
Create a reservation with only room_type (to_assign = True),
regardless of the rest of the fields the priority must be 1
NOTE:
WORK FLOW PRIORITY COMPUTE
Check reservation priority
--------
1 - TO ASSIGN, ARRIVAL DELAYED, DEPARTURE DELAYED (= 1)
2 - CANCELLED with pending amount (= 2)
3 - DONE with pending amount (= 3)
4 - ONBOARD with pending amount (= days for checkout)
5 - CONFIRM/DRAFT with arrival in less than 3 days (= 2 * days for checkin)
6 - ONBOARD all paid (= 3 * days for checkout)
7 - DONE with days from checkout < 1 (= 6)
8 - CONFIRM/DRAFT with arrival between 3 and 20 days (= 2 * days for checkin)
9 - CONFIRM/DRAFT with arrival in more than 20 days (= 4 * days for checkin)
10 - DONE with days from checkout < 15 (= 5 * days from checkout)
11 - DONE with days from checkout between 15 and 90 included (= 10 * days from checkout)
12 - DONE with days from checkout > 90 (= 100 * days from checkout)
"""
# ARRANGE
self.create_common_scenario()
r1 = self.env["pms.reservation"].create(
# ACT
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today() + datetime.timedelta(days=3),
"checkout": fields.date.today() + datetime.timedelta(days=4),
"checkin": fields.date.today() + datetime.timedelta(days=30),
"checkout": fields.date.today() + datetime.timedelta(days=31),
"room_type_id": self.room_type_double.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
r2 = self.env["pms.reservation"].create(
computed_priority = res.priority
# ASSERT
error_msm = (
(
"The priority of a reservation to be assigned \
should be %d and this is %d"
)
% (1, computed_priority)
)
self.assertEqual(
computed_priority,
1,
error_msm,
)
@freeze_time("1981-11-10")
def test_arrival_delayed_priority_reservation(self):
"""
Arrival delayed reservation must have priority = 1
------
Create a reservation with checkin date yesterday, and without checkin action,
regardless of the rest of the fields the priority must be 1
"""
# ARRANGE
self.create_common_scenario()
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today() + datetime.timedelta(days=-1),
"checkout": fields.date.today() + datetime.timedelta(days=1),
"preferred_room_id": self.room1.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
# ACT
res.auto_arrival_delayed()
computed_priority = res.priority
# ASSERT
error_msm = (
(
"The priority of a arrival delayed reservation \
should be %d and this is %d"
)
% (1, computed_priority)
)
self.assertEqual(
computed_priority,
1,
error_msm,
)
@freeze_time("1981-11-10")
def test_departure_delayed_priority_reservation(self):
"""
To departure delayed reservation must have priority = 1
------
Create a reservation and make the work flow to onboard state,
using jump dates, we make the reservation should have left yesterday,
regardless of the rest of the fields the priority must be 1
"""
# ARRANGE
self.create_common_scenario()
freezer = freeze_time("1981-10-08")
freezer.start()
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=1),
"room_type_id": self.room_type_double.id,
"preferred_room_id": self.room2.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
r2.action_assign()
# ACT
reservations = self.env["pms.reservation"].search(
[("pms_property_id", "=", self.property.id)]
host1 = self.env["res.partner"].create(
{
"firstname": "Pepe",
"lastname": "Paz",
"email": "pepe@example.com",
"birthdate_date": "1995-12-10",
"gender": "male",
}
)
checkin1 = self.env["pms.checkin.partner"].create(
{
"partner_id": host1.id,
"reservation_id": res.id,
"document_type": self.id_category.id,
"document_number": "77156490T",
"document_expedition_date": fields.date.today()
+ datetime.timedelta(days=665),
}
)
checkin1.action_on_board()
freezer.stop()
# ACT
res.auto_departure_delayed()
computed_priority = res.priority
# ASSERT
self.assertEqual(r1, reservations[0])
error_msm = (
(
"The priority of a departure delayed reservation \
should be %d and this is %d"
)
% (1, computed_priority)
)
self.assertEqual(
computed_priority,
1,
error_msm,
)
@freeze_time("1981-11-10")
def test_cancelled_pending_amount_priority_reservation(self):
"""
Cancelled with pending payments reservation must have priority = 2
------
create a reservation and cancel it ensuring that there are
pending payments in it, the priority must be 2
"""
# ARRANGE
self.create_common_scenario()
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today() + datetime.timedelta(days=55),
"checkout": fields.date.today() + datetime.timedelta(days=56),
"preferred_room_id": self.room2.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
# ACT
res.action_cancel()
computed_priority = res.priority
# ASSERT
error_msm = (
(
"The priority of a cancelled reservation with pending amount \
should be %d and this is %d"
)
% (2, computed_priority)
)
self.assertEqual(
computed_priority,
2,
error_msm,
)
@freeze_time("1981-11-01")
def test_order_priority_checkin(self):
# TODO: refact to tests priority flow defined above
# ARRANGE
self.create_common_scenario()
r1 = self.env["pms.reservation"].create(
@@ -798,6 +965,7 @@ class TestPmsReservations(common.SavepointCase):
@freeze_time("1981-11-01")
def test_order_priority_checkout(self):
# TODO: refact to tests priority flow defined above
# ARRANGE
self.create_common_scenario()
self.host1 = self.env["res.partner"].create(
@@ -869,6 +1037,7 @@ class TestPmsReservations(common.SavepointCase):
@freeze_time("1981-11-01")
def test_order_priority_state_onboard_and_pending_amount(self):
# TODO: refact to tests priority flow defined above
# ARRANGE
self.create_common_scenario()
host = self.env["res.partner"].create(