[ADD] pms-pwa: actions checkout, cancel & assign on reservation (#49)

This commit is contained in:
Miguel Padin
2021-02-10 21:10:32 +01:00
committed by GitHub
parent 33b0903f54
commit 41a1f66a75
2 changed files with 101 additions and 11 deletions

View File

@@ -1476,16 +1476,23 @@ class PmsReservation(models.Model):
def action_cancel(self): def action_cancel(self):
for record in self: for record in self:
cancel_reason = ( if not record.left_for_cancel:
"intime" raise UserError(_("This reservation cannot be cancelled"))
if self._context.get("no_penalty", False) else:
else record.compute_cancelation_reason() cancel_reason = (
) "intime"
if self._context.get("no_penalty", False): if self._context.get("no_penalty", False)
_logger.info("Modified Reservation - No Penalty") else record.compute_cancelation_reason()
record.write({"state": "cancelled", "cancelled_reason": cancel_reason}) )
# record._compute_cancelled_discount() if self._context.get("no_penalty", False):
record.folio_id._compute_amount() _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): def compute_cancelation_reason(self):
self.ensure_one() self.ensure_one()
@@ -1552,7 +1559,7 @@ class PmsReservation(models.Model):
def action_reservation_checkout(self): def action_reservation_checkout(self):
for record in 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")) raise UserError(_("This reservation cannot be check out"))
record.state = "done" record.state = "done"
if record.checkin_partner_ids: if record.checkin_partner_ids:

View File

@@ -681,3 +681,86 @@ class TestPmsReservations(TestHotel):
) )
# ASSERT # ASSERT
self.assertEqual(r1, reservations[0]) 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.")