[ADD] Shared Room avail manage

This commit is contained in:
Dario Lodeiros
2021-08-11 11:37:03 +02:00
parent bafd2c75bd
commit 2c7dae07cb
5 changed files with 545 additions and 54 deletions

View File

@@ -19,22 +19,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -1,6 +1,7 @@
import datetime
from odoo import fields
from odoo.exceptions import ValidationError
from .common import TestPms
@@ -24,7 +25,7 @@ class TestPmsSharedRoom(TestPms):
)
# create room type
self.room_type_shared = self.env["pms.room.type"].create(
self.room_type_test = self.env["pms.room.type"].create(
{
"pms_property_ids": [self.pms_property1.id],
"name": "Shared Test",
@@ -47,9 +48,8 @@ class TestPmsSharedRoom(TestPms):
{
"pms_property_id": self.pms_property1.id,
"name": "Shared 101",
"room_type_id": self.room_type_shared.id,
"room_type_id": self.room_type_test.id,
"capacity": 2,
"extra_beds_allowed": 1,
}
)
@@ -85,7 +85,7 @@ class TestPmsSharedRoom(TestPms):
}
)
def test_not_avail_beds_with_room_occupied(self):
def test_count_avail_beds_with_room_occupied(self):
"""
Check that not allow to create a bed reservation with a room occupied
----------------
@@ -118,7 +118,7 @@ class TestPmsSharedRoom(TestPms):
"Beds avaialbility should be 0 for room occupied",
)
def test_not_avail_shared_room_with_one_bed_occupied(self):
def test_count_avail_shared_room_with_one_bed_occupied(self):
"""
Check that not allow to create a shared room reservation with a bed occupied
----------------
@@ -145,17 +145,132 @@ class TestPmsSharedRoom(TestPms):
self.pms_property1.with_context(
checkin=today,
checkout=tomorrow,
room_type_id=self.room_type_shared.id,
room_type_id=self.room_type_test.id,
).availability,
0,
"Shared Room avaialbility should be 0 if it has a bed occupied",
)
def test_avail_beds_with_one_bed_occupied(self):
def test_avail_in_room_type_with_shared_rooms(self):
"""
Check the avail of a bed when it has a room with other beds occupied
Check that a shared room's bed occupied not
affect the avail on other rooms with the
same room type
----------------
Create a room1's bed (it has 2 beds) reservation and check that the beds avail = 1
Create other room like room_type_test (room2)
Create a room1's bed reservation and check that the room1
Check that room_type_test real avail is 1
"""
# ARRANGE
today = fields.date.today()
tomorrow = fields.date.today() + datetime.timedelta(days=1)
self.room2 = self.env["pms.room"].create(
{
"pms_property_id": self.pms_property1.id,
"name": "Shared 102",
"room_type_id": self.room_type_test.id,
"capacity": 2,
}
)
# 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_test.id,
).availability,
1,
"Room not shared affect by the shared room's avail with the same type",
)
def test_count_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
res1 = 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,
}
)
res1.flush()
# ASSERT
self.assertEqual(
self.pms_property1.with_context(
checkin=today,
checkout=tomorrow,
room_type_id=self.room_type_bed.id,
).availability,
1,
"Beds avaialbility should be 1 if it has 1 of 2 beds occupied",
)
def test_not_avail_beds_with_room_occupied(self):
"""
Check that not allow to select a bed with a room occupied
----------------
Create a room1 reservation and check that the beds are not available
"""
# 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.assertNotIn(
self.r1bed1.id,
self.pms_property1.with_context(
checkin=today,
checkout=tomorrow,
room_type_id=self.room_type_bed.id,
).free_room_ids.ids,
"room's bed should not be available " "because the entire room is reserved",
)
def test_not_avail_shared_room_with_one_bed_occupied(self):
"""
Check that not allow to select a shared
room with a bed occupied
----------------
Create a room1's bed reservation and check
that the room1 real avail is not available
"""
# ARRANGE
@@ -173,6 +288,193 @@ class TestPmsSharedRoom(TestPms):
}
)
# ASSERT
self.assertNotIn(
self.room1.id,
self.pms_property1.with_context(
checkin=today,
checkout=tomorrow,
room_type_id=self.room_type_bed.id,
).free_room_ids.ids,
"Entire Shared room should not be available "
"becouse it has a bed occupied",
)
def test_avail_beds_with_one_bed_occupied(self):
"""
Check the select 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 other bed is avail
"""
# 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.assertIn(
self.r1bed2.id,
self.pms_property1.with_context(
checkin=today,
checkout=tomorrow,
room_type_id=self.room_type_bed.id,
).free_room_ids.ids,
"The bed2 of the shared room should be available",
)
def test_not_allowed_reservation_in_bed_with_room_occuppied(self):
"""
Check the constrain that not allow to create a reservation in a bed in a
room with other reservation like shared
----------------
Create a room1's reservation and the try to create a reservation
in the room1's bed, we expect an error
"""
# ARRANGE
today = fields.date.today()
tomorrow = fields.date.today() + datetime.timedelta(days=1)
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,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError,
msg="Reservation created on a bed whose room was already occupied",
):
r_test = 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,
}
)
r_test.flush()
def test_not_allowed_reservation_in_shared_room_with_bed_occuppied(self):
"""
Check the constrain that not allow to create a reservation
in a shared room in a bed reservation
----------------
Create a room1's bed reservation and the try to create
a reservation in the room1, we expect an error
"""
# ARRANGE
today = fields.date.today()
tomorrow = fields.date.today() + datetime.timedelta(days=1)
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,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError,
msg="Reservation created in a full shared "
"room that already had beds occupied",
):
r_test = 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,
}
)
r_test.flush()
def check_room_shared_availability_released_when_canceling_bed_reservations(self):
"""
Check that check availability in shared room is
released when canceling bed reservations
----------------
Create a room1's bed reservation and then cancel it,
check that the room1 real avail is 1
"""
# ARRANGE
today = fields.date.today()
tomorrow = fields.date.today() + datetime.timedelta(days=1)
# ACT
r1 = 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,
}
)
r1.action_cancel()
# ASSERT
self.assertEqual(
self.pms_property1.with_context(
checkin=today,
checkout=tomorrow,
room_type_id=self.room_type_test.id,
).availability,
1,
"The parent room avail dont update " "when cancel child room reservation",
)
def check_bed_availability_released_when_canceling_parent_room_reservations(self):
"""
Check that check availability in child room is
released when canceling the parent rooms
----------------
Create a room1 reservation and then cancel it,
check that the beds real avail is 2
"""
# ARRANGE
today = fields.date.today()
tomorrow = fields.date.today() + datetime.timedelta(days=1)
# ACT
r1 = 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,
}
)
r1.action_cancel()
# ASSERT
self.assertEqual(
self.pms_property1.with_context(
@@ -180,6 +482,6 @@ class TestPmsSharedRoom(TestPms):
checkout=tomorrow,
room_type_id=self.room_type_bed.id,
).availability,
1,
"Shared Room avaialbility should be 0 if it has a bed occupied",
2,
"The child room avail dont update when " "cancel parent room reservation",
)