[IMP] Set to_assign to False when preferred_room_id is manually set

This commit is contained in:
Dario Lodeiros
2021-06-13 11:28:58 +02:00
parent 0892c57f9d
commit 7ddc341d8e
3 changed files with 27 additions and 2 deletions

View File

@@ -313,9 +313,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 +615,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,17 @@ 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
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

@@ -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"