mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Checkin Flow Assigned-Unassigned
This commit is contained in:
@@ -16,9 +16,14 @@ class PmsCheckinPartner(models.Model):
|
||||
return self.env.user.pms_property_id
|
||||
|
||||
# Fields declaration
|
||||
identifier = fields.Char(
|
||||
"Identifier",
|
||||
compute="_compute_identifier",
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
"res.partner",
|
||||
required=True,
|
||||
domain="[('is_company', '=', False)]",
|
||||
)
|
||||
reservation_id = fields.Many2one("pms.reservation")
|
||||
@@ -26,49 +31,67 @@ class PmsCheckinPartner(models.Model):
|
||||
"pms.folio",
|
||||
compute="_compute_folio_id",
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
pms_property_id = fields.Many2one(
|
||||
"pms.property", default=_get_default_pms_property, required=True
|
||||
)
|
||||
name = fields.Char("E-mail", related="partner_id.name")
|
||||
name = fields.Char("Name", related="partner_id.name")
|
||||
email = fields.Char("E-mail", related="partner_id.email")
|
||||
mobile = fields.Char("Mobile", related="partner_id.mobile")
|
||||
arrival = fields.Datetime("Enter")
|
||||
departure = fields.Datetime("Exit")
|
||||
completed_data = fields.Boolean(compute="_compute_completed_data", store=True)
|
||||
state = fields.Selection(
|
||||
selection=[
|
||||
("draft", "Pending arrival"),
|
||||
("draft", "Unkown Guest"),
|
||||
("precheckin", "Pending arrival"),
|
||||
("onboard", "On Board"),
|
||||
("done", "Out"),
|
||||
("cancelled", "Cancelled"),
|
||||
],
|
||||
string="State",
|
||||
compute="_compute_state",
|
||||
store=True,
|
||||
readonly=True,
|
||||
default=lambda *a: "draft",
|
||||
)
|
||||
|
||||
# Compute
|
||||
@api.depends("reservation_id", "folio_id", "reservation_id.room_id")
|
||||
def _compute_identifier(self):
|
||||
for record in self:
|
||||
# TODO: Identifier
|
||||
if record.reservation_id.filtered("room_id"):
|
||||
checkins = record.reservation_id.checkin_partner_ids
|
||||
record.identifier = (
|
||||
record.reservation_id.room_id.name + "-" + str(len(checkins) - 1)
|
||||
)
|
||||
elif record.folio_id:
|
||||
record.identifier = record.folio_id.name + "-" + str(len(checkins) - 1)
|
||||
else:
|
||||
record.identifier = False
|
||||
|
||||
@api.depends("reservation_id", "reservation_id.folio_id")
|
||||
def _compute_folio_id(self):
|
||||
for record in self:
|
||||
for record in self.filtered("reservation_id"):
|
||||
record.folio_id = record.reservation_id.folio_id
|
||||
|
||||
@api.depends(lambda self: self._checkin_mandatory_fields(), "state")
|
||||
def _compute_completed_data(self):
|
||||
self.completed_data = False
|
||||
@api.depends(lambda self: self._checkin_mandatory_fields(), "reservation_id.state")
|
||||
def _compute_state(self):
|
||||
for record in self:
|
||||
if any(
|
||||
not getattr(self, field) for field in record._checkin_mandatory_fields()
|
||||
):
|
||||
record.completed_data = False
|
||||
break
|
||||
record.completed_data = True
|
||||
if record.reservation_id.state == "cancelled":
|
||||
record.state = "cancelled"
|
||||
elif record.state in ("draft", "cancelled"):
|
||||
if any(
|
||||
not getattr(self, field)
|
||||
for field in record._checkin_mandatory_fields()
|
||||
):
|
||||
record.state = "draft"
|
||||
else:
|
||||
record.state = "precheckin"
|
||||
elif not record.state:
|
||||
record.state = "draft"
|
||||
|
||||
def _checkin_mandatory_fields(self):
|
||||
return ["name"]
|
||||
return ["name", "email"]
|
||||
|
||||
# Constraints and onchanges
|
||||
|
||||
|
||||
@@ -186,7 +186,14 @@ class PmsReservation(models.Model):
|
||||
readonly=False,
|
||||
)
|
||||
# TODO: Warning Mens to update pricelist
|
||||
checkin_partner_ids = fields.One2many("pms.checkin.partner", "reservation_id")
|
||||
checkin_partner_ids = fields.One2many(
|
||||
"pms.checkin.partner",
|
||||
"reservation_id",
|
||||
compute="_compute_checkin_partner_ids",
|
||||
store=True,
|
||||
readonly=False,
|
||||
ondelete="restrict",
|
||||
)
|
||||
count_pending_arrival = fields.Integer(
|
||||
"Pending Arrival",
|
||||
compute="_compute_count_pending_arrival",
|
||||
@@ -558,12 +565,48 @@ class PmsReservation(models.Model):
|
||||
# TODO: Warning change de pricelist?
|
||||
reservation.pricelist_id = pricelist_id
|
||||
|
||||
@api.depends("adults")
|
||||
def _compute_checkin_partner_ids(self):
|
||||
for reservation in self:
|
||||
assigned_checkins = reservation.checkin_partner_ids.filtered(
|
||||
lambda c: c.state in ("precheckin", "onboard", "done")
|
||||
)
|
||||
unassigned_checkins = reservation.checkin_partner_ids.filtered(
|
||||
lambda c: c.state not in ("draft")
|
||||
)
|
||||
leftover_unassigneds_count = (
|
||||
len(assigned_checkins) + len(unassigned_checkins) - reservation.adults
|
||||
)
|
||||
if len(assigned_checkins) > reservation.adults:
|
||||
raise UserError(
|
||||
_("Remove some of the leftover assigned checkins first")
|
||||
)
|
||||
elif leftover_unassigneds_count > 0:
|
||||
for i in range(0, len(unassigned_checkins)):
|
||||
unassigned_checkins[i].unlink()
|
||||
elif reservation.adults > len(reservation.checkin_partner_ids):
|
||||
checkins_lst = []
|
||||
count_new_checkins = reservation.adults - len(
|
||||
reservation.checkin_partner_ids
|
||||
)
|
||||
for _i in range(0, count_new_checkins):
|
||||
checkins_lst.append(
|
||||
(
|
||||
0,
|
||||
False,
|
||||
{
|
||||
"reservation_id": reservation.id,
|
||||
},
|
||||
)
|
||||
)
|
||||
reservation.checkin_partner_ids = checkins_lst
|
||||
|
||||
@api.depends("checkin_partner_ids", "checkin_partner_ids.state")
|
||||
def _compute_count_pending_arrival(self):
|
||||
for reservation in self:
|
||||
reservation.count_pending_arrival = reservation.adults - len(
|
||||
reservation.count_pending_arrival = len(
|
||||
reservation.checkin_partner_ids.filtered(
|
||||
lambda c: c.state in ("onboard", "done")
|
||||
lambda c: c.state in ("draft", "precheckin")
|
||||
)
|
||||
)
|
||||
|
||||
@@ -577,13 +620,11 @@ class PmsReservation(models.Model):
|
||||
/ reservation.adults
|
||||
)
|
||||
|
||||
@api.depends("checkin_partner_ids", "checkin_partner_ids.completed_data")
|
||||
@api.depends("checkin_partner_ids", "checkin_partner_ids.state")
|
||||
def _compute_pending_checkin_data(self):
|
||||
for reservation in self:
|
||||
reservation.pending_checkin_data = reservation.adults - len(
|
||||
reservation.checkin_partner_ids.filtered(
|
||||
lambda c: c.state != "cancelled" and c.completed_data
|
||||
)
|
||||
reservation.pending_checkin_data = len(
|
||||
reservation.checkin_partner_ids.filtered(lambda c: c.state in ("draft"))
|
||||
)
|
||||
|
||||
@api.depends("pending_checkin_data")
|
||||
@@ -810,11 +851,13 @@ class PmsReservation(models.Model):
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("checkin_partner_ids", "adults")
|
||||
def _max_checkin_partner_ids(self):
|
||||
for record in self:
|
||||
if len(record.checkin_partner_ids) > record.adults + record.children:
|
||||
raise models.ValidationError(_("The room already is completed"))
|
||||
# @api.constrains("checkin_partner_ids", "adults")
|
||||
# def _max_checkin_partner_ids(self):
|
||||
# for record in self:
|
||||
# if len(record.checkin_partner_ids) != record.adults:
|
||||
# raise models.ValidationError(
|
||||
# _("Reservation Adults and Checkins does not match")
|
||||
# )
|
||||
|
||||
# @api.constrains("reservation_type", "partner_id")
|
||||
# def _check_partner_reservation(self):
|
||||
|
||||
@@ -250,10 +250,6 @@ class PmsReservationLine(models.Model):
|
||||
line.reservation_id.tax_ids,
|
||||
line.reservation_id.company_id,
|
||||
)
|
||||
<<<<<<< HEAD
|
||||
# _logger.info(line.price)
|
||||
=======
|
||||
>>>>>>> [DEL] delete auto_booking field
|
||||
# TODO: Out of service 0 amount
|
||||
else:
|
||||
line.price = line._origin.price
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
</group>
|
||||
<group name="group_left">
|
||||
<field name="reservation_id" />
|
||||
<field name="folio_id" />
|
||||
<field name="identifier" />
|
||||
<field name="state" />
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
@@ -57,8 +60,9 @@
|
||||
icon="fa-2x fa-check-circle"
|
||||
name="action_on_board"
|
||||
help="Get in"
|
||||
attrs="{'invisible': [('state','!=','draft')]}"
|
||||
attrs="{'invisible': [('state','!=','preconfirm')]}"
|
||||
/>
|
||||
<field name="identifier" />
|
||||
<field name="partner_id" required="True" />
|
||||
<field name="mobile" />
|
||||
<field name="email" />
|
||||
@@ -86,9 +90,10 @@
|
||||
class="oe_stat_button"
|
||||
icon="fa fa-2x fa-check-circle"
|
||||
name="action_on_board"
|
||||
attrs="{'invisible':[('state','not in', ['draft'])]}"
|
||||
attrs="{'invisible':[('state','not in', ['preconfirm'])]}"
|
||||
help="Get in"
|
||||
/>
|
||||
<field name="identifier" />
|
||||
<field
|
||||
name="partner_id"
|
||||
required="True"
|
||||
|
||||
@@ -716,8 +716,10 @@
|
||||
/>
|
||||
<field
|
||||
name="state"
|
||||
decoration-success="state == 'done'"
|
||||
decoration-success="state == 'onboard'"
|
||||
decoration-info="state == 'confirm'"
|
||||
decoration-danger="state == 'cancelled'"
|
||||
decoration-primary="state == 'draft'"
|
||||
widget="badge"
|
||||
optional="show"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user