[IMP]pms: Checkin create compute flow

This commit is contained in:
Darío Lodeiros
2021-02-19 18:11:34 +01:00
parent b72e087b56
commit 5967157b3d
4 changed files with 44 additions and 42 deletions

View File

@@ -195,41 +195,42 @@ class PmsCheckinPartner(models.Model):
def create(self, vals):
# The checkin records are created automatically from adult depends
# if you try to create one manually, we update one unassigned checkin
if not self._context.get("auto_create_checkin"):
reservation_id = vals.get("reservation_id")
if reservation_id:
reservation = self.env["pms.reservation"].browse(reservation_id)
draft_checkins = reservation.checkin_partner_ids.filtered(
lambda c: c.state == "draft"
)
if len(draft_checkins) > 0:
draft_checkins[0].write(vals)
return draft_checkins[0]
elif vals.get("identifier", _("New")) == _("New") or "identifier" not in vals:
pms_property_id = (
self.env.user.get_active_property_ids()[0]
if "pms_property_id" not in vals
else vals["pms_property_id"]
reservation_id = vals.get("reservation_id")
if reservation_id:
reservation = self.env["pms.reservation"].browse(reservation_id)
else:
raise ValidationError(
_("Is mandatory indicate the reservation on the checkin")
)
vals["identifier"] = (
self.env["ir.sequence"]
.search(
[
("code", "=", "pms.checkin.partner"),
"|",
("pms_property_id", "=", pms_property_id),
("pms_property_id", "=", False),
]
draft_checkins = reservation.checkin_partner_ids.filtered(
lambda c: c.state == "draft"
)
if len(reservation.checkin_partner_ids) < reservation.adults:
if vals.get("identifier", _("New")) == _("New") or "identifier" not in vals:
pms_property_id = (
self.env.user.get_active_property_ids()[0]
if "pms_property_id" not in vals
else vals["pms_property_id"]
)
vals["identifier"] = (
self.env["ir.sequence"]
.search(
[
("code", "=", "pms.checkin.partner"),
"|",
("pms_property_id", "=", pms_property_id),
("pms_property_id", "=", False),
]
)
._next_do()
or _("New")
)
._next_do()
or _("New")
)
return super(PmsCheckinPartner, self).create(vals)
if len(draft_checkins) > 0:
draft_checkins[0].write(vals)
return draft_checkins[0]
raise ValidationError(
_(
"Either the reservation is not being indicated or it is \
not possible to create the proposed check-in in this reservation"
)
_("Is not possible to create the proposed check-in in this reservation")
)
def write(self, vals):

View File

@@ -748,9 +748,7 @@ class PmsReservation(models.Model):
},
)
)
reservation.with_context(
{"auto_create_checkin": True}
).checkin_partner_ids = checkins_lst
reservation.checkin_partner_ids = checkins_lst
@api.depends("checkin_partner_ids", "checkin_partner_ids.state")
def _compute_count_pending_arrival(self):
@@ -1226,13 +1224,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:
raise models.ValidationError(
_("The room already is completed (%s)", record.name)
)
# @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(
# _("The room already is completed (%s)", record.name)
# )
@api.constrains("adults")
def _check_adults(self):

View File

@@ -123,4 +123,4 @@ class ResPartner(models.Model):
@api.model
def _get_key_fields(self):
return ["mobile", "email"]
return []

View File

@@ -661,6 +661,7 @@ class TestPmsReservations(TestHotel):
"pms_property_id": self.property.id,
}
)
r1.flush()
checkin = self.env["pms.checkin.partner"].create(
{
"partner_id": host.id,
@@ -749,6 +750,7 @@ class TestPmsReservations(TestHotel):
"pms_property_id": self.property.id,
}
)
r1.flush()
checkin = self.env["pms.checkin.partner"].create(
{
"partner_id": host.id,
@@ -756,6 +758,7 @@ class TestPmsReservations(TestHotel):
}
)
checkin.action_on_board()
checkin.flush()
# ACT
r1.action_reservation_checkout()