diff --git a/pms/__manifest__.py b/pms/__manifest__.py
index 8c9133b21..67bbce05c 100644
--- a/pms/__manifest__.py
+++ b/pms/__manifest__.py
@@ -65,7 +65,6 @@
"views/pms_room_type_class_views.xml",
"views/pms_availability_plan_views.xml",
"views/pms_availability_plan_rule_views.xml",
- "views/pms_shared_room_views.xml",
"views/res_partner_views.xml",
"views/product_pricelist_views.xml",
"views/product_pricelist_item_views.xml",
diff --git a/pms/models/__init__.py b/pms/models/__init__.py
index 2a7be0cf8..5bcb034f5 100644
--- a/pms/models/__init__.py
+++ b/pms/models/__init__.py
@@ -13,7 +13,6 @@ from . import pms_ubication
from . import pms_folio
from . import pms_reservation
from . import pms_room
-from . import pms_shared_room
from . import pms_amenity
from . import pms_amenity_type
from . import pms_room_type
diff --git a/pms/models/pms_room.py b/pms/models/pms_room.py
index 4c64cc214..59ad462ef 100644
--- a/pms/models/pms_room.py
+++ b/pms/models/pms_room.py
@@ -48,12 +48,20 @@ class PmsRoom(models.Model):
ondelete="restrict",
check_pms_properties=True,
)
- # TODO: design shared rooms
- shared_room_id = fields.Many2one(
- string="Shared Room",
- help="The room can be sold by beds",
- default=False,
- comodel_name="pms.shared.room",
+ parent_id = fields.Many2one(
+ string="Parent Room",
+ help="Indicates that this room is a child of another room",
+ comodel_name="pms.room",
+ ondelete="restrict",
+ check_pms_properties=True,
+ )
+ child_ids = fields.One2many(
+ string="Child Rooms",
+ help="Child rooms of the room",
+ comodel_name="pms.room",
+ inverse_name="parent_id",
+ ondelete="restrict",
+ check_pms_properties=True,
)
ubication_id = fields.Many2one(
string="Ubication",
@@ -146,10 +154,8 @@ class PmsRoom(models.Model):
def get_capacity(self, extra_bed=0):
for record in self:
- if not record.shared_room_id:
- if extra_bed > record.extra_beds_allowed:
- raise ValidationError(
- _("Extra beds can't be greater than allowed beds for this room")
- )
- return record.capacity + extra_bed
- return record.capacity
+ if extra_bed > record.extra_beds_allowed:
+ raise ValidationError(
+ _("Extra beds can't be greater than allowed beds for this room")
+ )
+ return record.capacity + extra_bed
diff --git a/pms/models/pms_room_type.py b/pms/models/pms_room_type.py
index 076465651..116b00caa 100644
--- a/pms/models/pms_room_type.py
+++ b/pms/models/pms_room_type.py
@@ -67,12 +67,6 @@ class PmsRoomType(models.Model):
help="Identification code for a room type",
required=True,
)
- # TODO: Session review to define shared room and "sales rooms packs"
- is_shared_room = fields.Boolean(
- string="Shared Room",
- help="This room type is reservation by beds",
- default=False,
- )
total_rooms_count = fields.Integer(
string="Total Rooms Count",
help="The number of rooms in a room type",
diff --git a/pms/models/pms_shared_room.py b/pms/models/pms_shared_room.py
deleted file mode 100644
index 8566db551..000000000
--- a/pms/models/pms_shared_room.py
+++ /dev/null
@@ -1,143 +0,0 @@
-# Copyright 2017 Alexandre Díaz
-# Copyright 2017 Dario Lodeiros
-# Copyright 2018 Pablo Quesada
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import _, api, fields, models
-from odoo.exceptions import ValidationError
-
-
-class PmsSharedRoom(models.Model):
- _name = "pms.shared.room"
- _description = "Shared Room"
- _order = "room_type_id, name"
- _check_pms_properties_auto = True
-
- name = fields.Char(
- string="Room Name", help="Name of the shared room", required=True
- )
- active = fields.Boolean(
- string="Active", help="Determines if shared room is active", default=True
- )
- sequence = fields.Integer(
- string="Sequence",
- help="Field used to change the position of the shared rooms in tree view."
- "Changing the position changes the sequence",
- required=True,
- )
- room_type_id = fields.Many2one(
- string="Room Type",
- help="Room type which the shared room belongs",
- comodel_name="pms.room.type",
- required=True,
- ondelete="restrict",
- domain=[("shared_room", "=", True)],
- )
- # TODO: properties relation
- pms_property_ids = fields.Many2many(
- string="Properties",
- help="Properties with access to the element;"
- " if not set, all properties can access",
- comodel_name="pms.property",
- relation="pms_shared_room_pms_property_rel",
- column1="shared_room_id",
- column2="pms_property_id",
- check_pms_properties=True,
- )
- ubication_id = fields.Many2one(
- string="Ubication",
- help="At which ubication the room is located.",
- comodel_name="pms.ubication",
- ondelete="restrict",
- )
- bed_ids = fields.One2many(
- string="Beds",
- help="Beds in one room",
- comodel_name="pms.room",
- inverse_name="shared_room_id",
- readonly=True,
- )
- beds = fields.Integer(
- string="Number Of Beds", help="Number of beds in a shared room"
- )
- description_sale = fields.Text(
- string="Sale Description",
- help="A description of the Product that you want to communicate to "
- " your customers. This description will be copied to every Sales "
- " Order, Delivery Order and Customer Invoice/Credit Note",
- translate=True,
- )
-
- @api.constrains("beds")
- def _constrain_beds(self):
- self.ensure_one()
- if self.beds < 1:
- raise ValidationError(_("Room beds can't be less than one"))
- if len(self.bed_ids) > self.beds:
- raise ValidationError(
- _(
- "If you want to eliminate beds in the \
- room you must deactivate the beds from your form"
- )
- )
- beds = []
- inactive_beds = self.env["pms.room"].search(
- [("active", "=", False), ("shared_room_id", "=", self.id)]
- )
- for i in range(len(self.bed_ids), self.beds):
- if inactive_beds:
- bed = inactive_beds[0]
- bed.update({"active": True})
- inactive_beds -= bed
- continue
- name = u"{} ({})".format(self.name, i + 1)
- bed_vals = {
- "name": name,
- "capacity": 1,
- "room_type_id": self.room_type_id.id,
- "sequence": self.sequence,
- "ubication_id": self.ubication_id.id if self.ubication_id else False,
- "shared_room_id": self.id,
- }
- beds.append((0, False, bed_vals))
- if beds:
- self.update({"bed_ids": beds})
-
- @api.constrains("active")
- def _constrain_active(self):
- self.bed_ids.write(
- {
- "active": self.active,
- }
- )
-
- @api.constrains("room_type_id")
- def _constrain_room_type_id(self):
- self.bed_ids.write(
- {
- "room_type_id": self.room_type_id.id,
- }
- )
-
- @api.constrains("ubication_id")
- def _constrain_ubication_id(self):
- self.bed_ids.write(
- {
- "ubication_id": self.ubication_id.id,
- }
- )
-
- @api.constrains("sequence")
- def _constrain_sequence(self):
- self.bed_ids.write(
- {
- "sequence": self.sequence,
- }
- )
-
- @api.constrains("descrition_sale")
- def _constrain_descrition_sale(self):
- self.bed_ids.write(
- {
- "description_sale": self.descrition_sale,
- }
- )
diff --git a/pms/security/ir.model.access.csv b/pms/security/ir.model.access.csv
index d313323f6..544f75411 100644
--- a/pms/security/ir.model.access.csv
+++ b/pms/security/ir.model.access.csv
@@ -10,7 +10,6 @@ user_access_pms_board_service,user_access_pms_board_service,model_pms_board_serv
user_access_pms_checkin_partner,user_access_pms_checkin_partner,model_pms_checkin_partner,pms.group_pms_user,1,1,1,1
user_access_pms_room_type_class,user_access_pms_room_type_class,model_pms_room_type_class,pms.group_pms_user,1,0,0,0
user_access_pms_room,user_access_pms_room,model_pms_room,pms.group_pms_user,1,0,0,0
-user_access_shared_pms_room,user_access_pms_shared_room,model_pms_shared_room,pms.group_pms_user,1,0,0,0
user_access_pms_availability_plan_rule,user_access_pms_availability_plan_rule,model_pms_availability_plan_rule,pms.group_pms_user,1,0,0,0
user_access_pms_availability,user_access_pms_availability,model_pms_availability,pms.group_pms_user,1,1,1,0
user_access_pms_reservation,user_access_pms_reservation,model_pms_reservation,pms.group_pms_user,1,1,1,1
@@ -36,7 +35,6 @@ manager_access_pms_board_service,manager_access_pms_board_service,model_pms_boar
manager_access_pms_checkin_partner,manager_access_pms_checkin_partner,model_pms_checkin_partner,pms.group_pms_manager,1,1,1,1
manager_access_pms_room_type_class,manager_access_pms_room_type_class,model_pms_room_type_class,pms.group_pms_manager,1,1,1,1
manager_access_pms_room,manager_access_pms_room,model_pms_room,pms.group_pms_manager,1,1,1,1
-manager_access_pms_shared_room,manager_access_pms_shared_room,model_pms_shared_room,pms.group_pms_manager,1,1,1,1
manager_access_pms_availability_plan_rule,manager_access_pms_availability_plan_rule,model_pms_availability_plan_rule,pms.group_pms_manager,1,1,1,1
manager_access_pms_reservation,manager_access_pms_reservation,model_pms_reservation,pms.group_pms_manager,1,1,1,1
manager_access_pms_availability,manager_access_pms_availability,model_pms_availability,pms.group_pms_manager,1,1,1,0
diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py
index 2976ec8ca..4f21325fd 100644
--- a/pms/tests/__init__.py
+++ b/pms/tests/__init__.py
@@ -37,3 +37,4 @@ 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/tests/test_shared_room.py b/pms/tests/test_shared_room.py
new file mode 100644
index 000000000..0541a22a9
--- /dev/null
+++ b/pms/tests/test_shared_room.py
@@ -0,0 +1,185 @@
+import datetime
+
+from odoo import fields
+
+from .common import TestPms
+
+
+class TestPmsSharedRoom(TestPms):
+ def setUp(self):
+ super().setUp()
+ # create a room type availability
+ self.room_type_availability = self.env["pms.availability.plan"].create(
+ {
+ "name": "Availability plan for TEST",
+ "pms_pricelist_ids": [(6, 0, [self.pricelist1.id])],
+ }
+ )
+
+ self.bed_class = self.env["pms.room.type.class"].create(
+ {
+ "name": "Bed Class 1",
+ "default_code": "B1",
+ }
+ )
+
+ # create room type
+ self.room_type_shared = self.env["pms.room.type"].create(
+ {
+ "pms_property_ids": [self.pms_property1.id],
+ "name": "Shared Test",
+ "default_code": "SHT",
+ "class_id": self.room_type_class1.id,
+ }
+ )
+
+ self.room_type_bed = self.env["pms.room.type"].create(
+ {
+ "pms_property_ids": [self.pms_property1.id],
+ "name": "Bed Type Test",
+ "default_code": "BTT",
+ "class_id": self.bed_class.id,
+ }
+ )
+
+ # create shared room
+ self.room1 = self.env["pms.room"].create(
+ {
+ "pms_property_id": self.pms_property1.id,
+ "name": "Shared 101",
+ "room_type_id": self.room_type_shared.id,
+ "capacity": 2,
+ "extra_beds_allowed": 1,
+ }
+ )
+
+ # create beds in room1
+ self.r1bed1 = self.env["pms.room"].create(
+ {
+ "pms_property_id": self.pms_property1.id,
+ "name": "101 (1)",
+ "room_type_id": self.room_type_bed.id,
+ "capacity": 1,
+ "parent_id": self.room1.id,
+ }
+ )
+
+ self.r1bed2 = self.env["pms.room"].create(
+ {
+ "pms_property_id": self.pms_property1.id,
+ "name": "101 (2)",
+ "room_type_id": self.room_type_bed.id,
+ "capacity": 2,
+ "parent_id": self.room1.id,
+ }
+ )
+
+ # create partner
+ self.partner1 = self.env["res.partner"].create(
+ {
+ "firstname": "Jaime",
+ "lastname": "García",
+ "email": "jaime@example.com",
+ "birthdate_date": "1983-03-01",
+ "gender": "male",
+ }
+ )
+
+ def test_not_avail_beds_with_room_occupied(self):
+ """
+ Check that not allow to create a bed reservation with a room occupied
+ ----------------
+ Create a room1 reservation and check that the beds room real avail is 0
+ """
+
+ # ARRANGE
+ today = fields.date.today()
+ tomorrow = fields.date.today() + datetime.timedelta(days=1)
+
+ # ACT
+ self.env["pms.reservation"].create(
+ {
+ "partner_id": self.partner1.id,
+ "preferred_room_id": self.room1.id,
+ "checkin": today,
+ "checkout": tomorrow,
+ "pms_property_id": self.pms_property1.id,
+ }
+ )
+
+ # ASSERT
+ self.assertEqual(
+ self.pms_property1.with_context(
+ checkin=today,
+ checkout=tomorrow,
+ room_type_id=self.room_type_bed.id,
+ ).availability,
+ 0,
+ "Beds avaialbility should be 0 for room occupied",
+ )
+
+ def test_not_avail_shared_room_with_one_bed_occupied(self):
+ """
+ Check that not allow to create a shared room reservation with a bed occupied
+ ----------------
+ Create a room1's bed reservation and check that the room1 real avail is 0
+ """
+
+ # ARRANGE
+ today = fields.date.today()
+ tomorrow = fields.date.today() + datetime.timedelta(days=1)
+
+ # ACT
+ self.env["pms.reservation"].create(
+ {
+ "partner_id": self.partner1.id,
+ "preferred_room_id": self.r1bed1.id,
+ "checkin": today,
+ "checkout": tomorrow,
+ "pms_property_id": self.pms_property1.id,
+ }
+ )
+
+ # ASSERT
+ self.assertEqual(
+ self.pms_property1.with_context(
+ checkin=today,
+ checkout=tomorrow,
+ room_type_id=self.room_type_shared.id,
+ ).availability,
+ 0,
+ "Shared Room avaialbility should be 0 if it has a bed occupied",
+ )
+
+ def test_avail_beds_with_one_bed_occupied(self):
+ """
+ Check the avail of a bed when it has a room with other beds occupied
+ ----------------
+ Create a room1's bed (it has 2 beds) reservation and check that the beds avail = 1
+ """
+
+ # ARRANGE
+ today = fields.date.today()
+ tomorrow = fields.date.today() + datetime.timedelta(days=1)
+
+ # ACT
+ self.env["pms.reservation"].create(
+ {
+ "partner_id": self.partner1.id,
+ "preferred_room_id": self.r1bed1.id,
+ "checkin": today,
+ "checkout": tomorrow,
+ "pms_property_id": self.pms_property1.id,
+ }
+ )
+
+ # ASSERT
+ self.assertEqual(
+ self.pms_property1.with_context(
+ checkin=today,
+ checkout=tomorrow,
+ room_type_id=self.room_type_bed.id,
+ ).availability,
+ 1,
+ "Shared Room avaialbility should be 0 if it has a bed occupied",
+ )
diff --git a/pms/views/pms_room_type_views.xml b/pms/views/pms_room_type_views.xml
index 22965b472..e88714a4b 100644
--- a/pms/views/pms_room_type_views.xml
+++ b/pms/views/pms_room_type_views.xml
@@ -37,7 +37,6 @@
-
diff --git a/pms/views/pms_room_views.xml b/pms/views/pms_room_views.xml
index 40094bdf7..05b7fcc4c 100644
--- a/pms/views/pms_room_views.xml
+++ b/pms/views/pms_room_views.xml
@@ -24,15 +24,7 @@
-
-
+
@@ -43,25 +35,11 @@
invisible="0"
force_save="1"
/>
-
+
-
-
-
+
+
+
@@ -90,10 +68,7 @@
-
+
diff --git a/pms/views/pms_shared_room_views.xml b/pms/views/pms_shared_room_views.xml
deleted file mode 100644
index 68c9871c6..000000000
--- a/pms/views/pms_shared_room_views.xml
+++ /dev/null
@@ -1,133 +0,0 @@
-
-
-
- pms.shared.room.form
- pms.shared.room
-
-
-
-
-
- pms.shared.room.kanban
- pms.shared.room
- kanban
-
-
- false
-
-
-
-
-
-
-
- -
-
-
-
-
- -
- Room Type:
-
-
- -
-
- Beds
-
-
-
-
-
-
-
-
-
-
-
-
- pms.shared.room.search
- pms.shared.room
-
-
-
-
-
-
-
-
-
- pms.shared.room.tree
- pms.shared.room
-
-
-
-
-
-
-
-
-
-
- Shared Room
- pms.shared.room
-
-
- kanban,tree,form
-
-
-