Merge PR #16 into 14.0

Signed-off-by DarioLodeiros
This commit is contained in:
OCA-git-bot
2021-06-16 11:17:21 +00:00
4 changed files with 115 additions and 3 deletions

View File

@@ -87,6 +87,7 @@ class PmsReservation(models.Model):
copy=False,
store=True,
comodel_name="pms.room.type",
ondelete="restrict",
compute="_compute_room_type_id",
tracking=True,
check_pms_properties=True,
@@ -313,9 +314,9 @@ class PmsReservation(models.Model):
)
to_assign = fields.Boolean(
string="To Assign",
help="Technical field",
help="It is True if the room of the reservation has been assigned "
"automatically, False if it was confirmed by a person in charge",
default=True,
tracking=True,
)
state = fields.Selection(
string="State",
@@ -615,6 +616,12 @@ class PmsReservation(models.Model):
@api.depends("preferred_room_id")
def _compute_room_type_id(self):
"""
This method set False to_assign when the user
directly chooses the preferred_room_id,
otherwise, action_assign will be used when the user manually confirms
or changes the preferred_room_id of the reservation
"""
for reservation in self:
if reservation.preferred_room_id and not reservation.room_type_id:
reservation.room_type_id = reservation.preferred_room_id.room_type_id.id

View File

@@ -173,6 +173,19 @@ class PmsReservationLine(models.Model):
and not line.room_id
):
free_room_select = True if reservation.preferred_room_id else False
# Check if the room assigment is manual or automatic to set the
# to_assign value on reservation
# REVIEW: SRP Issue?¿ (set reservation to_assign value on
# compute_room_id in reservation_line)
if (
free_room_select
and reservation.preferred_room_id.id
not in reservation.reservation_line_ids.room_id.ids
):
# This case is a preferred_room_id manually assigned
reservation.to_assign = False
# we get the rooms available for the entire stay
rooms_available = self.env["pms.availability.plan"].rooms_available(
checkin=line.reservation_id.checkin,

View File

@@ -788,8 +788,92 @@ class TestPmsReservations(common.SavepointCase):
# ASSERT
self.assertEqual(r1, reservations[0])
@freeze_time("1981-11-01")
def test_reservation_action_assign(self):
"""
Checks the correct operation of the assign method
---------------
Create a new reservation with only room_type(autoassign -> to_assign = True),
and the we call to action_assign method to confirm the assignation
"""
self.create_common_scenario()
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=1),
"room_type_id": self.room_type_double.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
# ACT
res.action_assign()
# ASSERT
self.assertFalse(res.to_assign, "The reservation should be marked as assigned")
def test_reservation_auto_assign_on_create(self):
"""
When creating a reservation with a specific room,
it is not necessary to mark it as to be assigned
---------------
Create a new reservation with specific preferred_room_id,
"to_assign" should be set to false automatically
"""
# ARRANGE
self.create_common_scenario()
# ACT
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=1),
"preferred_room_id": self.room1.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
# ASSERT
self.assertFalse(
res.to_assign, "Reservation with preferred_room_id set to to_assign = True"
)
def test_reservation_auto_assign_after_create(self):
"""
When assigning a room manually to a reservation marked "to be assigned",
this field should be automatically unchecked
---------------
Create a new reservation without preferred_room_id (only room_type),
"to_assign" is True, then set preferred_room_id and "to_assign" should
be set to false automatically
"""
# ARRANGE
self.create_common_scenario()
# set the priority of the rooms to control the room chosen by auto assign
self.room1.sequence = 1
self.room2.sequence = 2
res = self.env["pms.reservation"].create(
{
"checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=1),
"room_type_id": self.room_type_double.id,
"partner_id": self.env.ref("base.res_partner_12").id,
"pms_property_id": self.property.id,
}
)
# ACT
# res shoul be room1 in preferred_room_id (minor sequence)
res.preferred_room_id = self.room2.id
# ASSERT
self.assertFalse(
res.to_assign,
"The reservation should be marked as assigned automatically \
when assigning the specific room",
)
def test_reservation_to_assign_on_create(self):
# TEST CASE
# the reservation action assign
# change the reservation to 'to_assign' = False

View File

@@ -15,6 +15,7 @@
<field name="splitted" invisible="True" />
<field name="tax_ids" invisible="1" />
<field name="checkin_partner_count" invisible="1" />
<field name="to_assign" invisible="1" />
<button
name="confirm"
string="Confirm"
@@ -22,6 +23,13 @@
type="object"
attrs="{'invisible':[('state','not in',('draft','cancelled'))]}"
/>
<button
name="action_assign"
string="Confirm Assigned Room"
class="oe_highlight"
type="object"
attrs="{'invisible':['|',('preferred_room_id','=',False),('to_assign', '=', False)]}"
/>
<button
name="action_cancel"
string="Cancel Reservation"