From d2a45b70ef89320fff967c9418fa04f61185e6a6 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Wed, 11 Aug 2021 12:15:27 +0200 Subject: [PATCH] [IMP] Views Shared room --- pms/models/pms_reservation_line.py | 31 ------------------------- pms/models/pms_room.py | 28 +++++++++++++++++++++-- pms/tests/__init__.py | 36 +++++++++++++++--------------- pms/views/pms_room_views.xml | 26 +++++++++++++++++++++ 4 files changed, 70 insertions(+), 51 deletions(-) diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index 3a03a2a4e..6331997fa 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -470,34 +470,3 @@ class PmsReservationLine(models.Model): ) if duplicated: raise ValidationError(_("Duplicated reservation line date")) - - @api.constrains("room_id", "date") - def constrains_parent_room_avail(self): - for record in self: - if record.room_id and record.room_id.parent_id and record.date: - if self.env["pms.availability"].get_occupied_parent_rooms( - room=record.room_id.parent_id, - checkin=record.date, - checkout=record.date + datetime.timedelta(1), - pms_property_id=record.room_id.pms_property_id.id, - ): - raise ValidationError( - _("Room %s is occupied in this date by the parent room %s") - % record.room_id.display_name, - record.room_id.parent_id.display_name, - ) - - @api.constrains("room_id", "date") - def constrains_childs_room_avail(self): - for record in self: - if record.room_id and record.room_id.child_ids and record.date: - if self.env["pms.availability"].get_occupied_child_rooms( - rooms=record.room_id.child_ids, - checkin=record.date, - checkout=record.date + datetime.timedelta(1), - pms_property_id=record.room_id.pms_property_id.id, - ): - raise ValidationError( - _("Room %s is occupied in this date by the child rooms") - % record.room_id.display_name - ) diff --git a/pms/models/pms_room.py b/pms/models/pms_room.py index 59ad462ef..0c03d5cc7 100644 --- a/pms/models/pms_room.py +++ b/pms/models/pms_room.py @@ -60,7 +60,6 @@ class PmsRoom(models.Model): help="Child rooms of the room", comodel_name="pms.room", inverse_name="parent_id", - ondelete="restrict", check_pms_properties=True, ) ubication_id = fields.Many2one( @@ -87,7 +86,13 @@ class PmsRoom(models.Model): column2="amenity_id", check_pms_properties=True, ) - + is_shared_room = fields.Boolean( + string="Is a Shared Room", + help="allows you to reserve units " " smaller than the room itself (eg beds)", + compute="_compute_is_shared_room", + readonly=False, + store=True, + ) description_sale = fields.Text( string="Sale Description", help="A description of the Product that you want to communicate to " @@ -105,6 +110,14 @@ class PmsRoom(models.Model): ) ] + @api.depends("child_ids") + def _compute_is_shared_room(self): + for record in self: + if record.child_ids: + record.is_shared_room = True + elif not record.is_shared_room: + record.is_shared_room = False + def name_get(self): result = [] for room in self: @@ -130,6 +143,17 @@ class PmsRoom(models.Model): ) ) + @api.constrains("is_shared_room") + def _check_shared_room(self): + for record in self: + if record.is_shared_room and not record.child_ids: + raise ValidationError( + _( + "The reservation units are required \ + on shared rooms." + ) + ) + @api.model def _check_adults(self, reservation, service_line_ids=False): for line in reservation.reservation_line_ids: diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index dc88cb8a9..4f21325fd 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -19,22 +19,22 @@ # along with this program. If not, see . # ############################################################################## -# 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_room -# 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_multiproperty +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_room +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_multiproperty from . import test_shared_room diff --git a/pms/views/pms_room_views.xml b/pms/views/pms_room_views.xml index 05b7fcc4c..2fa9aca2d 100644 --- a/pms/views/pms_room_views.xml +++ b/pms/views/pms_room_views.xml @@ -38,6 +38,11 @@ + + @@ -66,6 +71,27 @@ + + + + + + + + + + + + + +