diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index a455231d3..038bb5642 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -1476,16 +1476,23 @@ class PmsReservation(models.Model): def action_cancel(self): for record in self: - cancel_reason = ( - "intime" - if self._context.get("no_penalty", False) - else record.compute_cancelation_reason() - ) - if self._context.get("no_penalty", False): - _logger.info("Modified Reservation - No Penalty") - record.write({"state": "cancelled", "cancelled_reason": cancel_reason}) - # record._compute_cancelled_discount() - record.folio_id._compute_amount() + if not record.left_for_cancel: + raise UserError(_("This reservation cannot be cancelled")) + else: + cancel_reason = ( + "intime" + if self._context.get("no_penalty", False) + else record.compute_cancelation_reason() + ) + if self._context.get("no_penalty", False): + _logger.info("Modified Reservation - No Penalty") + record.write({"state": "cancelled", "cancelled_reason": cancel_reason}) + # record._compute_cancelled_discount() + record.folio_id._compute_amount() + + def action_assign(self): + for record in self: + record.to_assign = False def compute_cancelation_reason(self): self.ensure_one() @@ -1552,7 +1559,7 @@ class PmsReservation(models.Model): def action_reservation_checkout(self): for record in self: - if record.state not in ("onboard", "no_checkout"): + if not record.left_for_checkout: raise UserError(_("This reservation cannot be check out")) record.state = "done" if record.checkin_partner_ids: diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index c2cceeffe..0f8e980c0 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -681,3 +681,86 @@ class TestPmsReservations(TestHotel): ) # ASSERT self.assertEqual(r1, reservations[0]) + + @freeze_time("1981-11-01") + def test_reservation_action_assign(self): + # TEST CASE + # the reservation action assign + # change the reservation to 'to_assign' = False + # ARRANGE + self.create_common_scenario() + 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, + "partner_id": self.env.ref("base.res_partner_12").id, + "pms_property_id": self.property.id, + } + ) + # ACT + res.action_assign() + # ASSERT + self.assertFalse(res.to_assign, "The reservation should be marked as assigned") + + @freeze_time("1981-11-01") + def test_reservation_action_cancel(self): + # TEST CASE + # the reservation action cancel + # change the state of the reservation to 'cancelled' + # ARRANGE + self.create_common_scenario() + 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, + "partner_id": self.env.ref("base.res_partner_12").id, + "pms_property_id": self.property.id, + } + ) + # ACT + res.action_cancel() + # ASSERT + self.assertEqual(res.state, + 'cancelled', + "The reservation should be cancelled") + + @freeze_time("1981-11-01") + def test_reservation_action_checkout(self): + # TEST CASE + # the reservation action checkout + # change the state of the reservation to 'done' + # ARRANGE + self.create_common_scenario() + host = self.env["res.partner"].create( + { + "name": "Miguel", + "phone": "654667733", + "email": "miguel@example.com", + } + ) + 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, + } + ) + checkin = self.env["pms.checkin.partner"].create( + { + "partner_id": host.id, + "reservation_id": r1.id, + } + ) + checkin.action_on_board() + + # ACT + r1.action_reservation_checkout() + + # ASSERT + self.assertEqual(r1.state, + "done", + "The reservation status should be done after checkout.")