From d86a6b0226a3676df0445e6d175675aa78364b0b Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Sat, 19 Jun 2021 21:49:55 +0200 Subject: [PATCH 1/4] [IMP] Compute reservation priority --- pms/data/cron_jobs.xml | 15 +++++ pms/models/pms_checkin_partner.py | 3 +- pms/models/pms_reservation.py | 70 ++++++++++++++++---- pms/tests/__init__.py | 41 ++++++------ pms/tests/test_pms_reservation.py | 103 +++++++++++++++++++++--------- 5 files changed, 167 insertions(+), 65 deletions(-) diff --git a/pms/data/cron_jobs.xml b/pms/data/cron_jobs.xml index c780b2373..2cd3c2029 100644 --- a/pms/data/cron_jobs.xml +++ b/pms/data/cron_jobs.xml @@ -46,5 +46,20 @@ /> model.autocheckout() + + Recompute priority on reservations + 1 + + days + -1 + + code + + + model.update_daily_priority_reservation() + diff --git a/pms/models/pms_checkin_partner.py b/pms/models/pms_checkin_partner.py index e7278cb67..8d7679153 100644 --- a/pms/models/pms_checkin_partner.py +++ b/pms/models/pms_checkin_partner.py @@ -591,8 +591,7 @@ class PmsCheckinPartner(models.Model): "arrival": fields.Datetime.now(), } record.update(vals) - if record.reservation_id.allowed_checkin: - record.reservation_id.state = "onboard" + record.reservation_id.state = "onboard" def action_done(self): for record in self.filtered(lambda c: c.state == "onboard"): diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 0ac07d9f1..1737dd74f 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -15,7 +15,7 @@ class PmsReservation(models.Model): _name = "pms.reservation" _description = "Reservation" _inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"] - _order = "priority desc, create_date desc, write_date desc" + _order = "priority asc, create_date desc, write_date desc" # TODO: # consider near_to_checkin & pending_notifications to order _check_pms_properties_auto = True @@ -594,22 +594,58 @@ class PmsReservation(models.Model): for record in self: record.date_order = datetime.datetime.today() - # TODO: - # consider near_to_checkin & pending_notifications to order - @api.depends("checkin") + @api.depends( + "checkin", + "checkout", + "state", + "folio_payment_state", + "to_assign", + ) def _compute_priority(self): + # TODO: Notifications priority for record in self: - record.priority = 0 + if record.to_assign: + record.priority = 1 + elif record.state in ("arrival_delayed", "departure_delayed"): + record.priority = 1 + elif record.state == "cancelled": + if record.pending_amount > 0: + record.priority = 2 + elif record.state == "onboard": + record.priority = record.onboard_priority() + elif record.state in ("draf", "confirm"): + record.priority = record.reservations_future_priority() + elif record.state == "done": + record.priority = record.reservations_past_priority() - # we can give weights for each condition - if not record.to_assign: - record.priority += 1 - if not record.allowed_checkin: - record.priority += 10 - if record.allowed_checkout: - record.priority += 100 - if record.state == "onboard" and record.folio_pending_amount > 0: - record.priority += 1000 + def onboard_priority(self): + self.ensure_one() + if self.pending_amount > 0: + return (self.checkout - fields.date.today()).days + + 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 + elif days_for_checkin < 20: + return 15 + days_for_checkin + else: + return 50 + days_for_checkin + + def reservations_past_priority(self): + self.ensure_one() + if self.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 @api.depends("pricelist_id", "room_type_id") def _compute_board_service_room_id(self): @@ -1596,6 +1632,12 @@ class PmsReservation(models.Model): res.message_post(subject=_("No Checkins!"), subtype="mt_comment", body=msg) return True + @api.model + def update_daily_priority_reservation(self): + reservations = self.env["pms.reservation"].search([("priority", "<", 1000)]) + reservations._compute_priority() + return True + def overbooking_button(self): self.ensure_one() self.overbooking = not self.overbooking diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index e736526ea..246cf9a3b 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -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 diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index a8cfcbf4e..6678ebc1e 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -757,7 +757,7 @@ class TestPmsReservations(common.SavepointCase): "pms_property_id": self.property.id, } ) - r1.to_assign = False + r1.action_assign() # ACT reservations = self.env["pms.reservation"].search( [("pms_property_id", "=", self.property.id)] @@ -766,9 +766,61 @@ class TestPmsReservations(common.SavepointCase): self.assertEqual(r1, reservations[0]) @freeze_time("1981-11-01") - def test_order_priority_allowed_checkin(self): + def test_order_priority_checkin(self): # ARRANGE self.create_common_scenario() + r1 = self.env["pms.reservation"].create( + { + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=2), + "preferred_room_id": self.room1.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "pms_property_id": self.property.id, + } + ) + r2 = self.env["pms.reservation"].create( + { + "checkin": fields.date.today() + datetime.timedelta(days=1), + "checkout": fields.date.today() + datetime.timedelta(days=2), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "pms_property_id": self.property.id, + } + ) + r1.flush() + r2.flush() + # ACT + reservations = self.env["pms.reservation"].search( + [("pms_property_id", "=", self.property.id)] + ) + # ASSERT + self.assertEqual(r1, reservations[0]) + + @freeze_time("1981-11-01") + def test_order_priority_checkout(self): + # ARRANGE + self.create_common_scenario() + id_category = self.env["res.partner.id_category"].create( + {"name": "DNI", "code": "D"} + ) + self.host1 = self.env["res.partner"].create( + { + "firstname": "Pepe", + "lastname": "Paz", + "email": "miguel@example.com", + "birthdate_date": "1995-12-10", + "gender": "male", + } + ) + self.host2 = self.env["res.partner"].create( + { + "firstname": "Pepe", + "lastname": "Paz", + "email": "Brais@example.com", + "birthdate_date": "1995-12-10", + "gender": "male", + } + ) r1 = self.env["pms.reservation"].create( { "checkin": fields.date.today(), @@ -778,46 +830,39 @@ class TestPmsReservations(common.SavepointCase): "pms_property_id": self.property.id, } ) - self.env["pms.reservation"].create( + r2 = self.env["pms.reservation"].create( { "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), + "checkout": fields.date.today() + datetime.timedelta(days=2), "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "pms_property_id": self.property.id, } ) - r1.allowed_checkin = False - # ACT - reservations = self.env["pms.reservation"].search( - [("pms_property_id", "=", self.property.id)] - ) - # ASSERT - self.assertEqual(r1, reservations[0]) - - @freeze_time("1981-11-01") - def test_order_priority_allowed_checkout(self): - # ARRANGE - self.create_common_scenario() - r1 = self.env["pms.reservation"].create( + checkin1 = self.env["pms.checkin.partner"].create( { - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), - "room_type_id": self.room_type_double.id, - "partner_id": self.env.ref("base.res_partner_12").id, - "pms_property_id": self.property.id, + "partner_id": self.host1.id, + "reservation_id": r1.id, + "document_type": id_category.id, + "document_number": "77156490T", + "document_expedition_date": fields.date.today() + + datetime.timedelta(days=665), } ) - self.env["pms.reservation"].create( + checkin2 = self.env["pms.checkin.partner"].create( { - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), - "room_type_id": self.room_type_double.id, - "partner_id": self.env.ref("base.res_partner_12").id, - "pms_property_id": self.property.id, + "partner_id": self.host1.id, + "reservation_id": r2.id, + "document_type": id_category.id, + "document_number": "55562998N", + "document_expedition_date": fields.date.today() + + datetime.timedelta(days=665), } ) - r1.allowed_checkout = True + checkin1.action_on_board() + checkin2.action_on_board() + r1.flush() + r2.flush() # ACT reservations = self.env["pms.reservation"].search( [("pms_property_id", "=", self.property.id)] From 95fb08fe1b8a0e6138855ba9a52d70981f497660 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Sun, 20 Jun 2021 07:43:59 +0200 Subject: [PATCH 2/4] [IMP] priority tests --- pms/models/pms_checkin_partner.py | 5 ++-- pms/models/pms_reservation.py | 6 +++++ pms/tests/__init__.py | 41 +++++++++++++++---------------- pms/tests/test_pms_reservation.py | 17 ++++++------- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/pms/models/pms_checkin_partner.py b/pms/models/pms_checkin_partner.py index 8d7679153..08af80e57 100644 --- a/pms/models/pms_checkin_partner.py +++ b/pms/models/pms_checkin_partner.py @@ -222,8 +222,9 @@ class PmsCheckinPartner(models.Model): ) def _compute_document_expedition_date(self): for record in self: - if record.partner_id and record.partner_id.id_numbers: - if not record.document_expedition_date: + if not record.document_expedition_date: + record.document_expedition_date = False + if record.partner_id and record.partner_id.id_numbers: record.document_expedition_date = record.partner_id.id_numbers[ 0 ].valid_from diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 1737dd74f..9b4a80a69 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -611,6 +611,12 @@ class PmsReservation(models.Model): 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 + ) elif record.state == "onboard": record.priority = record.onboard_priority() elif record.state in ("draf", "confirm"): diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 246cf9a3b..e736526ea 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -20,24 +20,23 @@ # ############################################################################## 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 diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 6678ebc1e..09f891e31 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -741,14 +741,14 @@ class TestPmsReservations(common.SavepointCase): self.create_common_scenario() r1 = self.env["pms.reservation"].create( { - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=1), + "checkin": fields.date.today() + datetime.timedelta(days=3), + "checkout": fields.date.today() + datetime.timedelta(days=4), "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, "pms_property_id": self.property.id, } ) - self.env["pms.reservation"].create( + r2 = self.env["pms.reservation"].create( { "checkin": fields.date.today(), "checkout": fields.date.today() + datetime.timedelta(days=1), @@ -757,7 +757,7 @@ class TestPmsReservations(common.SavepointCase): "pms_property_id": self.property.id, } ) - r1.action_assign() + r2.action_assign() # ACT reservations = self.env["pms.reservation"].search( [("pms_property_id", "=", self.property.id)] @@ -800,9 +800,6 @@ class TestPmsReservations(common.SavepointCase): def test_order_priority_checkout(self): # ARRANGE self.create_common_scenario() - id_category = self.env["res.partner.id_category"].create( - {"name": "DNI", "code": "D"} - ) self.host1 = self.env["res.partner"].create( { "firstname": "Pepe", @@ -843,7 +840,7 @@ class TestPmsReservations(common.SavepointCase): { "partner_id": self.host1.id, "reservation_id": r1.id, - "document_type": id_category.id, + "document_type": self.id_category.id, "document_number": "77156490T", "document_expedition_date": fields.date.today() + datetime.timedelta(days=665), @@ -851,9 +848,9 @@ class TestPmsReservations(common.SavepointCase): ) checkin2 = self.env["pms.checkin.partner"].create( { - "partner_id": self.host1.id, + "partner_id": self.host2.id, "reservation_id": r2.id, - "document_type": id_category.id, + "document_type": self.id_category.id, "document_number": "55562998N", "document_expedition_date": fields.date.today() + datetime.timedelta(days=665), From d936eda7ac80a0f290a6de26aec88a85e0ac3937 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Sun, 20 Jun 2021 10:00:37 +0200 Subject: [PATCH 3/4] [IMP] basic test cases for priority reservations compute --- pms/demo/pms_folio.xml | 1 + pms/models/pms_reservation.py | 52 ++++---- pms/tests/__init__.py | 41 +++---- pms/tests/test_pms_reservation.py | 193 ++++++++++++++++++++++++++++-- 4 files changed, 232 insertions(+), 55 deletions(-) diff --git a/pms/demo/pms_folio.xml b/pms/demo/pms_folio.xml index 63d8651bc..43231d71c 100644 --- a/pms/demo/pms_folio.xml +++ b/pms/demo/pms_folio.xml @@ -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, diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 9b4a80a69..4ac0592e9 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -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: diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index e736526ea..246cf9a3b 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -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 diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 09f891e31..7242da8d8 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -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( From fc9af1cbf98c9fb29a341544aa03c0f427e9c5f8 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Sun, 20 Jun 2021 13:20:40 +0200 Subject: [PATCH 4/4] [IMP] complete test cases for priority reservations compute --- pms/models/pms_reservation.py | 2 +- pms/tests/__init__.py | 41 +- pms/tests/test_pms_reservation.py | 727 ++++++++++++++++++++++++------ 3 files changed, 621 insertions(+), 149 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 4ac0592e9..6ad6ccb8a 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -650,7 +650,7 @@ class PmsReservation(models.Model): if self.folio_pending_amount > 0: return 3 days_from_checkout = (fields.date.today() - self.checkout).days - if days_from_checkout < 1: + if days_from_checkout <= 1: return 6 elif days_from_checkout < 15: return 5 * days_from_checkout diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 246cf9a3b..e736526ea 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -20,24 +20,23 @@ # ############################################################################## 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 diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 7242da8d8..f435acf3b 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -754,13 +754,14 @@ class TestPmsReservations(common.SavepointCase): 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) + 8 - CONFIRM/DRAFT with arrival between 3 and 20 days (= 3 * 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 + expected_priority = 1 self.create_common_scenario() # ACT @@ -781,12 +782,12 @@ class TestPmsReservations(common.SavepointCase): "The priority of a reservation to be assigned \ should be %d and this is %d" ) - % (1, computed_priority) + % (expected_priority, computed_priority) ) self.assertEqual( computed_priority, - 1, + expected_priority, error_msm, ) @@ -799,6 +800,7 @@ class TestPmsReservations(common.SavepointCase): regardless of the rest of the fields the priority must be 1 """ # ARRANGE + expected_priority = 1 self.create_common_scenario() res = self.env["pms.reservation"].create( { @@ -820,12 +822,12 @@ class TestPmsReservations(common.SavepointCase): "The priority of a arrival delayed reservation \ should be %d and this is %d" ) - % (1, computed_priority) + % (expected_priority, computed_priority) ) self.assertEqual( computed_priority, - 1, + expected_priority, error_msm, ) @@ -839,6 +841,7 @@ class TestPmsReservations(common.SavepointCase): regardless of the rest of the fields the priority must be 1 """ # ARRANGE + expected_priority = 1 self.create_common_scenario() freezer = freeze_time("1981-10-08") freezer.start() @@ -883,12 +886,12 @@ class TestPmsReservations(common.SavepointCase): "The priority of a departure delayed reservation \ should be %d and this is %d" ) - % (1, computed_priority) + % (expected_priority, computed_priority) ) self.assertEqual( computed_priority, - 1, + expected_priority, error_msm, ) @@ -901,6 +904,7 @@ class TestPmsReservations(common.SavepointCase): pending payments in it, the priority must be 2 """ # ARRANGE + expected_priority = 2 self.create_common_scenario() res = self.env["pms.reservation"].create( { @@ -922,173 +926,642 @@ class TestPmsReservations(common.SavepointCase): "The priority of a cancelled reservation with pending amount \ should be %d and this is %d" ) - % (2, computed_priority) + % (expected_priority, computed_priority) ) self.assertEqual( computed_priority, - 2, + expected_priority, error_msm, ) - @freeze_time("1981-11-01") - def test_order_priority_checkin(self): - # TODO: refact to tests priority flow defined above + @freeze_time("1981-11-10") + def test_done_with_pending_amountpriority_reservation(self): + """ + Done with pending amount reservation must have priority = 3 + ------ + Create a reservation and make the work flow to onboard - done state, + using jump dates, we make the checkout reservation with pending amount, + regardless of the rest of the fields the priority must be 3 + """ # ARRANGE self.create_common_scenario() - r1 = self.env["pms.reservation"].create( + expected_priority = 3 + 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=2), - "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, - "pms_property_id": self.property.id, - } - ) - r2 = self.env["pms.reservation"].create( - { - "checkin": fields.date.today() + datetime.timedelta(days=1), - "checkout": fields.date.today() + datetime.timedelta(days=2), + "checkout": fields.date.today() + datetime.timedelta(days=1), "preferred_room_id": self.room2.id, "partner_id": self.env.ref("base.res_partner_12").id, "pms_property_id": self.property.id, } ) - r1.flush() - r2.flush() - # ACT - reservations = self.env["pms.reservation"].search( - [("pms_property_id", "=", self.property.id)] - ) - # ASSERT - self.assertEqual(r1, reservations[0]) - - @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( + host1 = self.env["res.partner"].create( { "firstname": "Pepe", "lastname": "Paz", - "email": "miguel@example.com", + "email": "pepe@example.com", "birthdate_date": "1995-12-10", "gender": "male", } ) - self.host2 = self.env["res.partner"].create( - { - "firstname": "Pepe", - "lastname": "Paz", - "email": "Brais@example.com", - "birthdate_date": "1995-12-10", - "gender": "male", - } - ) - r1 = 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, - "partner_id": self.env.ref("base.res_partner_12").id, - "pms_property_id": self.property.id, - } - ) - r2 = self.env["pms.reservation"].create( - { - "checkin": fields.date.today(), - "checkout": fields.date.today() + datetime.timedelta(days=2), - "room_type_id": self.room_type_double.id, - "partner_id": self.env.ref("base.res_partner_12").id, - "pms_property_id": self.property.id, - } - ) checkin1 = self.env["pms.checkin.partner"].create( { - "partner_id": self.host1.id, - "reservation_id": r1.id, + "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), } ) - checkin2 = self.env["pms.checkin.partner"].create( + checkin1.action_on_board() + + freezer.stop() + freezer = freeze_time("1981-10-09") + freezer.start() + + res.action_reservation_checkout() + + # ACT + res.auto_departure_delayed() + computed_priority = res.priority + freezer.stop() + + # ASSERT + error_msm = ( + ( + "The priority of a done reservation with pending amount\ + should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_onboard_with_pending_amount_priority_reservation(self): + """ + Onboard with pending amount reservation must have priority = days for checkout + ------ + Create a reservation with 3 nights and make the work flow to onboard, + using jump dates, we set today in 2 nights before checkout, + regardless of the rest of the fields the priority must be 2 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 3 + freezer = freeze_time("1981-10-08") + freezer.start() + res = self.env["pms.reservation"].create( { - "partner_id": self.host2.id, - "reservation_id": r2.id, + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=3), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "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": "55562998N", + "document_number": "77156490T", + "document_expedition_date": fields.date.today() + + datetime.timedelta(days=665), + } + ) + + # ACT + checkin1.action_on_board() + computed_priority = res.priority + freezer.stop() + + # ASSERT + error_msm = ( + ( + "The priority of a onboard with payment amount reservation \ + should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_confirm_arriva_lt_3_days_priority_reservation(self): + """ + Confirm reservation with arrival in less than 3 days, priority = 2 * days for checkout + ------ + Create a reservation with checkin date on 2 days + regardless of the rest of the fields the priority must be 2 * 2 = 4 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 4 + + # ACT + res = self.env["pms.reservation"].create( + { + "checkin": fields.date.today() + datetime.timedelta(days=2), + "checkout": fields.date.today() + datetime.timedelta(days=5), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "pms_property_id": self.property.id, + } + ) + computed_priority = res.priority + + # ASSERT + error_msm = ( + ( + "The priority of a confirm with less than 3 days for arrival \ + reservation should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_onboard_all_pay_priority_reservation(self): + """ + Onboard with all pay reservation must have priority = 3 * days for checkout + ------ + Create a reservation with 3 nights and make the work flow to onboard, + using jump dates, we set today in 2 nights before checkout, + regardless of the rest of the fields the priority must be 3 * 3 = 9 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 9 + res = self.env["pms.reservation"].create( + { + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=3), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "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), + } + ) + + # ACT + checkin1.action_on_board() + # REVIEW: set to 0 the price to avoid make the payment + # (config account company issues in test) + res.reservation_line_ids.write({"price": 0}) + computed_priority = res.priority + + # ASSERT + error_msm = ( + ( + "The priority of onboard all pay reservation \ + should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_done_yesterday_all_paid_amountpriority_reservation(self): + """ + Checkout yesterday without pending amount reservation must have priority = 6 + ------ + Create a reservation and make the work flow to onboard - done state, + using jump dates, we make the checkout reservation without pending amount, + and set today 1 day after, + regardless of the rest of the fields the priority must be 6 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 6 + 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), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "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() - checkin2.action_on_board() - r1.flush() - r2.flush() - # ACT - reservations = self.env["pms.reservation"].search( - [("pms_property_id", "=", self.property.id)] - ) - # ASSERT - self.assertEqual(r1, reservations[0]) - @freeze_time("1981-11-01") - def test_order_priority_state_onboard_and_pending_amount(self): - # TODO: refact to tests priority flow defined above + freezer.stop() + freezer = freeze_time("1981-10-09") + freezer.start() + + res.action_reservation_checkout() + # REVIEW: set to 0 the price to avoid make the payment + # (config account company issues in test) + res.reservation_line_ids.write({"price": 0}) + + # ACT + freezer.stop() + freezer = freeze_time("1981-10-10") + freezer.start() + + res.update_daily_priority_reservation() + computed_priority = res.priority + freezer.stop() + + # ASSERT + error_msm = ( + ( + "The priority of a done reservation without pending amount\ + and checkout yesterday should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_confirm_arriva_bt_3_and_20_days_priority_reservation(self): + """ + Confirm reservation with arrival between 3 and 20 days, priority = 3 * days for checkout + ------ + Create a reservation with checkin date on 15 days + regardless of the rest of the fields the priority must be 3 * 15 = 45 + """ # ARRANGE self.create_common_scenario() - host = self.env["res.partner"].create( + expected_priority = 45 + + # ACT + res = self.env["pms.reservation"].create( { - "name": "Miguel", - "mobile": "654667733", - "email": "miguel@example.com", - "birthdate_date": "1995-12-10", - "gender": "male", - } - ) - self.env["res.partner.id_number"].create( - { - "category_id": self.id_category.id, - "name": "30065089H", - "valid_from": datetime.date.today(), - "partner_id": host.id, - } - ) - r1 = 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, - "partner_id": host.id, - "pms_property_id": self.property.id, - } - ) - r1.flush() - checkin = self.env["pms.checkin.partner"].create( - { - "partner_id": host.id, - "reservation_id": r1.id, - } - ) - checkin.action_on_board() - 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, + "checkin": fields.date.today() + datetime.timedelta(days=15), + "checkout": fields.date.today() + datetime.timedelta(days=20), + "preferred_room_id": self.room2.id, "partner_id": self.env.ref("base.res_partner_12").id, "pms_property_id": self.property.id, } ) - # ACT - reservations = self.env["pms.reservation"].search( - [("pms_property_id", "=", self.property.id)] - ) + computed_priority = res.priority + # ASSERT - self.assertEqual(r1, reservations[0]) + error_msm = ( + ( + "The priority of a confirm with between 3 and 20 days for arrival \ + reservation should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_confirm_arrival_more_than_20_days_priority_reservation(self): + """ + Confirm reservation with arrival more than 20 days, priority = 4 * days for checkout + ------ + Create a reservation with checkin date on 21 days + regardless of the rest of the fields the priority must be 4 * 21 = 84 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 84 + + # ACT + res = self.env["pms.reservation"].create( + { + "checkin": fields.date.today() + datetime.timedelta(days=21), + "checkout": fields.date.today() + datetime.timedelta(days=25), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "pms_property_id": self.property.id, + } + ) + computed_priority = res.priority + + # ASSERT + error_msm = ( + ( + "The priority of a confirm with more than 20 days for arrival \ + reservation should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_done_checkout_lt_15_days_before_all_paid_priority_reservation(self): + """ + Checkout less than 15 days before without pending amount reservation + must have priority = 5 * days from checkout + ------ + Create a reservation and make the work flow to onboard - done state, + using jump dates, we make the checkout reservation without pending amount, + and set today 6 day after, + regardless of the rest of the fields the priority must be 6 * 5 = 30 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 30 + freezer = freeze_time("1981-10-09") + freezer.start() + res = self.env["pms.reservation"].create( + { + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=1), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "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() + freezer = freeze_time("1981-10-10") + freezer.start() + + res.action_reservation_checkout() + # REVIEW: set to 0 the price to avoid make the payment + # (config account company issues in test) + res.reservation_line_ids.write({"price": 0}) + + # ACT + freezer.stop() + freezer = freeze_time("1981-10-16") + freezer.start() + + res.update_daily_priority_reservation() + computed_priority = res.priority + freezer.stop() + + # ASSERT + error_msm = ( + ( + "The priority of a done reservation without pending amount\ + and checkout less than 15 days before should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_done_checkout_bt_30_and_90_days_before_all_paid_priority_reservation(self): + """ + Checkout between 30 and 90 days before without pending amount reservation + must have priority = 10 * days from checkout + ------ + Create a reservation and make the work flow to onboard - done state, + using jump dates, we make the checkout reservation without pending amount, + and set today 45 day after, + regardless of the rest of the fields the priority must be 10 * 45 = 450 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 450 + freezer = freeze_time("1981-10-09") + freezer.start() + res = self.env["pms.reservation"].create( + { + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=1), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "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() + freezer = freeze_time("1981-10-10") + freezer.start() + + res.action_reservation_checkout() + # REVIEW: set to 0 the price to avoid make the payment + # (config account company issues in test) + res.reservation_line_ids.write({"price": 0}) + + # ACT + freezer.stop() + freezer = freeze_time("1981-11-24") + freezer.start() + + res.update_daily_priority_reservation() + computed_priority = res.priority + freezer.stop() + + # ASSERT + error_msm = ( + ( + "The priority of a done reservation without pending amount\ + and checkout between 30 and 90 days before should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) + + @freeze_time("1981-11-10") + def test_done_checkout_mt_90_days_before_all_paid_priority_reservation(self): + """ + Checkout more than 90 days before without pending amount reservation + must have priority = 100 * days from checkout + ------ + Create a reservation and make the work flow to onboard - done state, + using jump dates, we make the checkout reservation without pending amount, + and set today 91 day after, + regardless of the rest of the fields the priority must be 100 * 91 = 9100 + """ + # ARRANGE + self.create_common_scenario() + expected_priority = 9100 + freezer = freeze_time("1981-10-09") + freezer.start() + res = self.env["pms.reservation"].create( + { + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=1), + "preferred_room_id": self.room2.id, + "partner_id": self.env.ref("base.res_partner_12").id, + "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() + freezer = freeze_time("1981-10-10") + freezer.start() + + res.action_reservation_checkout() + # REVIEW: set to 0 the price to avoid make the payment + # (config account company issues in test) + res.reservation_line_ids.write({"price": 0}) + + # ACT + freezer.stop() + freezer = freeze_time("1982-01-09") + freezer.start() + + res.update_daily_priority_reservation() + computed_priority = res.priority + freezer.stop() + + # ASSERT + error_msm = ( + ( + "The priority of a done reservation without pending amount\ + and checkout more than 90 days before should be %d and this is %d" + ) + % (expected_priority, computed_priority) + ) + + self.assertEqual( + computed_priority, + expected_priority, + error_msm, + ) def test_reservation_action_assign(self): """