From 8307a43ec5706989530b3931719aec000e19c073 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Mon, 28 Jun 2021 14:59:40 +0200 Subject: [PATCH] [FIX] test constrains adults and dates checkin/out --- pms/models/pms_reservation.py | 41 ++++++++++++++++--------------- pms/tests/test_pms_reservation.py | 6 ++--- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index c9bdc1614..155b329f8 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -789,6 +789,7 @@ class PmsReservation(models.Model): else: if not reservation.reservation_line_ids: reservation.reservation_line_ids = False + reservation.check_in_out_dates() @api.depends("board_service_room_id") def _compute_service_ids(self): @@ -1008,6 +1009,7 @@ class PmsReservation(models.Model): record.checkin = record.folio_id.reservation_ids[0].checkin else: record.checkin = fields.date.today() + record.check_in_out_dates() @api.depends("reservation_line_ids", "checkin") def _compute_checkout(self): @@ -1032,10 +1034,7 @@ class PmsReservation(models.Model): elif not record.checkout: record.checkout = False # date checking - if record.checkin and record.checkout and record.checkin >= record.checkout: - raise UserError( - _("The checkout date must be greater than the checkin date") - ) + record.check_in_out_dates() @api.depends("pms_property_id", "folio_id") def _compute_arrival_hour(self): @@ -1362,22 +1361,24 @@ class PmsReservation(models.Model): segmentation_ids = folio.segmentation_ids return segmentation_ids - # TODO: make this check on computes (checkin/checkout) - # @api.constrains("checkin", "checkout", "state", "preferred_room_id", "overbooking") - # def check_dates(self): - # """ - # 1.-When date_order is less then checkin date or - # Checkout date should be greater than the checkin date. - # 3.-Check the reservation dates are not occuped - # """ - # for record in self: - # if record.checkin >= record.checkout: - # raise ValidationError( - # _( - # "Room line Check In Date Should be \ - # less than the Check Out Date!" - # ) - # ) + def check_in_out_dates(self): + """ + 1.-When date_order is less then checkin date or + Checkout date should be greater than the checkin date. + 3.-Check the reservation dates are not occuped + """ + for record in self: + if ( + record.checkout + and record.checkout + and record.checkin >= record.checkout + ): + raise UserError( + _( + "Room line Check In Date Should be \ + less than the Check Out Date!" + ) + ) @api.constrains("reservation_line_ids") def check_consecutive_dates(self): diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 79cc449b8..fa0289411 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -2046,7 +2046,7 @@ class TestPmsReservations(common.SavepointCase): "name": "Host1", } ) - with self.assertRaises(ValidationError): + with self.assertRaises(UserError): self.env["pms.reservation"].create( { "checkin": fields.date.today() + datetime.timedelta(days=3), @@ -2066,8 +2066,8 @@ class TestPmsReservations(common.SavepointCase): with self.assertRaises(ValidationError): self.env["pms.reservation"].create( { - "checkin": fields.date.today() + datetime.timedelta(days=3), - "checkout": fields.date.today(), + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=3), "pms_property_id": self.property.id, "partner_id": self.host1.id, "room_type_id": self.room_type_double.id,