mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] pms: fix properties error board_service_room_type
This commit is contained in:
@@ -32,6 +32,8 @@ class PmsBoardServiceRoomType(models.Model):
|
|||||||
column1="pms_board_service_room_type_id",
|
column1="pms_board_service_room_type_id",
|
||||||
column2="pms_property_id",
|
column2="pms_property_id",
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
|
compute="_compute_pms_property_ids",
|
||||||
|
store=True,
|
||||||
)
|
)
|
||||||
pms_room_type_id = fields.Many2one(
|
pms_room_type_id = fields.Many2one(
|
||||||
string="Room Type",
|
string="Room Type",
|
||||||
@@ -62,6 +64,43 @@ class PmsBoardServiceRoomType(models.Model):
|
|||||||
help="Indicates if this board service is applied by default in the room type",
|
help="Indicates if this board service is applied by default in the room type",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.depends(
|
||||||
|
"pms_room_type_id",
|
||||||
|
"pms_room_type_id.pms_property_ids",
|
||||||
|
"pms_board_service_id",
|
||||||
|
"pms_board_service_id.pms_property_ids",
|
||||||
|
)
|
||||||
|
def _compute_pms_property_ids(self):
|
||||||
|
for record in self:
|
||||||
|
if (
|
||||||
|
record.pms_room_type_id.pms_property_ids
|
||||||
|
and record.pms_board_service_id.pms_property_ids
|
||||||
|
):
|
||||||
|
record.pms_property_ids = self.env["pms.property"].search(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
"in",
|
||||||
|
list(
|
||||||
|
set(record.pms_room_type_id.pms_property_ids.ids)
|
||||||
|
& set(record.pms_board_service_id.pms_property_ids.ids)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
elif (
|
||||||
|
record.pms_room_type_id.pms_property_ids
|
||||||
|
and not record.pms_board_service_id.pms_property_ids
|
||||||
|
):
|
||||||
|
record.pms_property_ids = record.pms_room_type_id.pms_property_ids
|
||||||
|
elif (
|
||||||
|
not record.pms_room_type_id.pms_property_ids
|
||||||
|
and record.pms_board_service_id.pms_property_ids
|
||||||
|
):
|
||||||
|
record.pms_property_ids = record.pms_board_service_id.pms_property_ids
|
||||||
|
else:
|
||||||
|
record.pms_property_ids = False
|
||||||
|
|
||||||
@api.depends("board_service_line_ids.amount")
|
@api.depends("board_service_line_ids.amount")
|
||||||
def _compute_board_amount(self):
|
def _compute_board_amount(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
@@ -107,28 +146,11 @@ class PmsBoardServiceRoomType(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
properties = False
|
# properties = False
|
||||||
if "pms_board_service_id" in vals:
|
if "pms_board_service_id" in vals:
|
||||||
vals.update(
|
vals.update(
|
||||||
self.prepare_board_service_reservation_ids(vals["pms_board_service_id"])
|
self.prepare_board_service_reservation_ids(vals["pms_board_service_id"])
|
||||||
)
|
)
|
||||||
board_service = self.env["pms.board.service"].browse(
|
|
||||||
vals["pms_board_service_id"]
|
|
||||||
)
|
|
||||||
properties = board_service.pms_property_ids
|
|
||||||
if "pms_room_type_id" in vals:
|
|
||||||
room_type = self.env["pms.room.type"].browse(vals["pms_room_type_id"])
|
|
||||||
properties = (
|
|
||||||
properties + room_type.pms_property_ids
|
|
||||||
if properties
|
|
||||||
else room_type.pms_property_ids
|
|
||||||
)
|
|
||||||
if properties:
|
|
||||||
vals.update(
|
|
||||||
{
|
|
||||||
"pms_property_ids": properties,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return super(PmsBoardServiceRoomType, self).create(vals)
|
return super(PmsBoardServiceRoomType, self).create(vals)
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|||||||
@@ -52,18 +52,246 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
|
|||||||
"checkin_sequence_id": self.checkin_sequence.id,
|
"checkin_sequence_id": self.checkin_sequence.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.board_service = self.env["pms.board.service"].create(
|
self.room_type_availability = self.env["pms.availability.plan"].create(
|
||||||
{
|
{"name": "Availability plan for TEST"}
|
||||||
"name": "Board Service",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# create room type class
|
||||||
self.room_type_class = self.env["pms.room.type.class"].create(
|
self.room_type_class = self.env["pms.room.type.class"].create(
|
||||||
{"name": "Room Type Class", "default_code": "SIN1"}
|
{"name": "Room", "default_code": "ROOM"}
|
||||||
)
|
)
|
||||||
self.room_type = self.env["pms.room.type"].create(
|
|
||||||
|
def test_create_rt_props_gt_bs_props(self):
|
||||||
|
# TEST CASE
|
||||||
|
# Create board service for a room type and the room type
|
||||||
|
# have MORE properties than the board service.
|
||||||
|
# Record of board_service_room_type should contain the
|
||||||
|
# board service properties.
|
||||||
|
|
||||||
|
# ARRANGE
|
||||||
|
self._create_common_scenario()
|
||||||
|
room_type_double = self.env["pms.room.type"].create(
|
||||||
{
|
{
|
||||||
"name": "Room Type",
|
"pms_property_ids": [self.property1.id, self.property2.id],
|
||||||
"default_code": "Type1",
|
"name": "Double Test",
|
||||||
|
"default_code": "DBL_Test",
|
||||||
"class_id": self.room_type_class.id,
|
"class_id": self.room_type_class.id,
|
||||||
|
"price": 25,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
board_service_test = self.board_service = self.env["pms.board.service"].create(
|
||||||
|
{
|
||||||
|
"name": "Test Board Service",
|
||||||
|
"default_code": "TPS",
|
||||||
|
"pms_property_ids": [self.property1.id],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ACT
|
||||||
|
new_bsrt = self.env["pms.board.service.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_room_type_id": room_type_double.id,
|
||||||
|
"pms_board_service_id": board_service_test.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ASSERT
|
||||||
|
self.assertEqual(
|
||||||
|
new_bsrt.pms_property_ids.ids,
|
||||||
|
board_service_test.pms_property_ids.ids,
|
||||||
|
"Record of board_service_room_type should contain the"
|
||||||
|
" board service properties.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_rt_props_lt_bs_props(self):
|
||||||
|
# TEST CASE
|
||||||
|
# Create board service for a room type and the room type
|
||||||
|
# have LESS properties than the board service.
|
||||||
|
# Record of board_service_room_type should contain the
|
||||||
|
# room types properties.
|
||||||
|
|
||||||
|
# ARRANGE
|
||||||
|
self._create_common_scenario()
|
||||||
|
room_type_double = self.env["pms.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_property_ids": [self.property1.id],
|
||||||
|
"name": "Double Test",
|
||||||
|
"default_code": "DBL_Test",
|
||||||
|
"class_id": self.room_type_class.id,
|
||||||
|
"price": 25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
board_service_test = self.board_service = self.env["pms.board.service"].create(
|
||||||
|
{
|
||||||
|
"name": "Test Board Service",
|
||||||
|
"default_code": "TPS",
|
||||||
|
"pms_property_ids": [self.property1.id, self.property2.id],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ACT
|
||||||
|
new_bsrt = self.env["pms.board.service.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_room_type_id": room_type_double.id,
|
||||||
|
"pms_board_service_id": board_service_test.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ASSERT
|
||||||
|
self.assertEqual(
|
||||||
|
new_bsrt.pms_property_ids.ids,
|
||||||
|
room_type_double.pms_property_ids.ids,
|
||||||
|
"Record of board_service_room_type should contain the"
|
||||||
|
" room types properties.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_rt_props_eq_bs_props(self):
|
||||||
|
# TEST CASE
|
||||||
|
# Create board service for a room type and the room type
|
||||||
|
# have THE SAME properties than the board service.
|
||||||
|
# Record of board_service_room_type should contain the
|
||||||
|
# room types properties that matchs with the board
|
||||||
|
# service properties
|
||||||
|
|
||||||
|
# ARRANGE
|
||||||
|
self._create_common_scenario()
|
||||||
|
room_type_double = self.env["pms.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_property_ids": [self.property1.id],
|
||||||
|
"name": "Double Test",
|
||||||
|
"default_code": "DBL_Test",
|
||||||
|
"class_id": self.room_type_class.id,
|
||||||
|
"price": 25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
board_service_test = self.board_service = self.env["pms.board.service"].create(
|
||||||
|
{
|
||||||
|
"name": "Test Board Service",
|
||||||
|
"default_code": "TPS",
|
||||||
|
"pms_property_ids": [self.property1.id],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ACT
|
||||||
|
new_bsrt = self.env["pms.board.service.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_room_type_id": room_type_double.id,
|
||||||
|
"pms_board_service_id": board_service_test.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ASSERT
|
||||||
|
self.assertTrue(
|
||||||
|
new_bsrt.pms_property_ids.ids == room_type_double.pms_property_ids.ids
|
||||||
|
and new_bsrt.pms_property_ids.ids
|
||||||
|
== board_service_test.pms_property_ids.ids,
|
||||||
|
"Record of board_service_room_type should contain the room "
|
||||||
|
"types properties and matchs with the board service properties",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_rt_no_props_and_bs_props(self):
|
||||||
|
# TEST CASE
|
||||||
|
# Create board service for a room type and the room type
|
||||||
|
# hasn't properties but the board services.
|
||||||
|
# Record of board_service_room_type should contain the
|
||||||
|
# board service properties.
|
||||||
|
|
||||||
|
# ARRANGE
|
||||||
|
self._create_common_scenario()
|
||||||
|
room_type_double = self.env["pms.room.type"].create(
|
||||||
|
{
|
||||||
|
"name": "Double Test",
|
||||||
|
"default_code": "DBL_Test",
|
||||||
|
"class_id": self.room_type_class.id,
|
||||||
|
"price": 25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
board_service_test = self.board_service = self.env["pms.board.service"].create(
|
||||||
|
{
|
||||||
|
"name": "Test Board Service",
|
||||||
|
"default_code": "TPS",
|
||||||
|
"pms_property_ids": [self.property1.id],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ACT
|
||||||
|
new_bsrt = self.env["pms.board.service.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_room_type_id": room_type_double.id,
|
||||||
|
"pms_board_service_id": board_service_test.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ASSERT
|
||||||
|
self.assertEqual(
|
||||||
|
new_bsrt.pms_property_ids.ids,
|
||||||
|
board_service_test.pms_property_ids.ids,
|
||||||
|
"Record of board_service_room_type should contain the"
|
||||||
|
" board service properties.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_rt_props_and_bs_no_props(self):
|
||||||
|
# TEST CASE
|
||||||
|
# Create board service for a room type and the board service
|
||||||
|
# hasn't properties but the room type.
|
||||||
|
# Record of board_service_room_type should contain the
|
||||||
|
# room type properties.
|
||||||
|
|
||||||
|
# ARRANGE
|
||||||
|
self._create_common_scenario()
|
||||||
|
room_type_double = self.env["pms.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_property_ids": [self.property1.id, self.property2.id],
|
||||||
|
"name": "Double Test",
|
||||||
|
"default_code": "DBL_Test",
|
||||||
|
"class_id": self.room_type_class.id,
|
||||||
|
"price": 25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
board_service_test = self.board_service = self.env["pms.board.service"].create(
|
||||||
|
{
|
||||||
|
"name": "Test Board Service",
|
||||||
|
"default_code": "TPS",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ACT
|
||||||
|
new_bsrt = self.env["pms.board.service.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_room_type_id": room_type_double.id,
|
||||||
|
"pms_board_service_id": board_service_test.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ASSERT
|
||||||
|
self.assertEqual(
|
||||||
|
new_bsrt.pms_property_ids.ids,
|
||||||
|
room_type_double.pms_property_ids.ids,
|
||||||
|
"Record of board_service_room_type should contain the"
|
||||||
|
" room type properties.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_rt_no_props_and_bs_no_props(self):
|
||||||
|
# TEST CASE
|
||||||
|
# Create board service for a room type and the board service
|
||||||
|
# has no properties and neither does the room type
|
||||||
|
# Record of board_service_room_type shouldnt contain properties.
|
||||||
|
|
||||||
|
# ARRANGE
|
||||||
|
self._create_common_scenario()
|
||||||
|
room_type_double = self.env["pms.room.type"].create(
|
||||||
|
{
|
||||||
|
"name": "Double Test",
|
||||||
|
"default_code": "DBL_Test",
|
||||||
|
"class_id": self.room_type_class.id,
|
||||||
|
"price": 25,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
board_service_test = self.board_service = self.env["pms.board.service"].create(
|
||||||
|
{
|
||||||
|
"name": "Test Board Service",
|
||||||
|
"default_code": "TPS",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ACT
|
||||||
|
new_bsrt = self.env["pms.board.service.room.type"].create(
|
||||||
|
{
|
||||||
|
"pms_room_type_id": room_type_double.id,
|
||||||
|
"pms_board_service_id": board_service_test.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# ASSERT
|
||||||
|
self.assertFalse(
|
||||||
|
new_bsrt.pms_property_ids.ids,
|
||||||
|
"Record of board_service_room_type shouldnt contain properties.",
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user