mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: overbooking reservation _compute
This commit is contained in:
@@ -496,8 +496,8 @@ class PmsReservation(models.Model):
|
|||||||
overbooking = fields.Boolean(
|
overbooking = fields.Boolean(
|
||||||
string="Is Overbooking",
|
string="Is Overbooking",
|
||||||
help="Indicate if exists overbooking",
|
help="Indicate if exists overbooking",
|
||||||
default=False,
|
compute="_compute_overbooking",
|
||||||
copy=False,
|
store=True,
|
||||||
)
|
)
|
||||||
nights = fields.Integer(
|
nights = fields.Integer(
|
||||||
string="Nights",
|
string="Nights",
|
||||||
@@ -1773,6 +1773,11 @@ class PmsReservation(models.Model):
|
|||||||
recs = self.search([]).filtered(lambda x: x.checkin_partner_pending_count > 0)
|
recs = self.search([]).filtered(lambda x: x.checkin_partner_pending_count > 0)
|
||||||
return [("id", "in", [x.id for x in recs])] if recs else []
|
return [("id", "in", [x.id for x in recs])] if recs else []
|
||||||
|
|
||||||
|
@api.depends("reservation_line_ids", "reservation_line_ids.overbooking")
|
||||||
|
def _compute_overbooking(self):
|
||||||
|
for record in self:
|
||||||
|
record.overbooking = any(record.reservation_line_ids.mapped("overbooking"))
|
||||||
|
|
||||||
def _get_default_segmentation(self):
|
def _get_default_segmentation(self):
|
||||||
folio = False
|
folio = False
|
||||||
segmentation_ids = False
|
segmentation_ids = False
|
||||||
@@ -2290,10 +2295,6 @@ class PmsReservation(models.Model):
|
|||||||
reservations._compute_priority()
|
reservations._compute_priority()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def overbooking_button(self):
|
|
||||||
self.ensure_one()
|
|
||||||
self.overbooking = not self.overbooking
|
|
||||||
|
|
||||||
def confirm(self):
|
def confirm(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
vals = {}
|
vals = {}
|
||||||
|
|||||||
@@ -245,10 +245,10 @@ class PmsReservationLine(models.Model):
|
|||||||
|
|
||||||
# if the preferred room is NOT available
|
# if the preferred room is NOT available
|
||||||
else:
|
else:
|
||||||
if self.env.context.get("force_overbooking"):
|
if (
|
||||||
line.overbooking = True
|
self.env.context.get("force_overbooking")
|
||||||
line.room_id = reservation.preferred_room_id
|
or not line.occupies_availability
|
||||||
elif not line.occupies_availability:
|
):
|
||||||
line.room_id = reservation.preferred_room_id
|
line.room_id = reservation.preferred_room_id
|
||||||
else:
|
else:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
@@ -275,7 +275,6 @@ class PmsReservationLine(models.Model):
|
|||||||
real_avail=True,
|
real_avail=True,
|
||||||
):
|
):
|
||||||
if self.env.context.get("force_overbooking"):
|
if self.env.context.get("force_overbooking"):
|
||||||
reservation.overbooking = True
|
|
||||||
line.room_id = reservation.room_type_id.room_ids.filtered(
|
line.room_id = reservation.room_type_id.room_ids.filtered(
|
||||||
lambda r: r.pms_property_id == line.pms_property_id
|
lambda r: r.pms_property_id == line.pms_property_id
|
||||||
)[0]
|
)[0]
|
||||||
@@ -408,7 +407,7 @@ class PmsReservationLine(models.Model):
|
|||||||
for line in self:
|
for line in self:
|
||||||
if (
|
if (
|
||||||
line.reservation_id.state == "cancel"
|
line.reservation_id.state == "cancel"
|
||||||
or line.reservation_id.overbooking
|
or line.overbooking
|
||||||
or line.is_reselling
|
or line.is_reselling
|
||||||
):
|
):
|
||||||
line.occupies_availability = False
|
line.occupies_availability = False
|
||||||
@@ -476,25 +475,19 @@ class PmsReservationLine(models.Model):
|
|||||||
discount = first_discount + cancel_discount
|
discount = first_discount + cancel_discount
|
||||||
line.price_day_total = line.price - discount
|
line.price_day_total = line.price - discount
|
||||||
|
|
||||||
@api.depends("reservation_id.overbooking")
|
@api.depends("room_id")
|
||||||
def _compute_overbooking(self):
|
def _compute_overbooking(self):
|
||||||
for record in self:
|
for record in self.filtered("room_id"):
|
||||||
if record.reservation_id.overbooking:
|
if record.occupies_availability and not record.overbooking:
|
||||||
real_avail = (
|
if self.env["pms.reservation.line"].search(
|
||||||
self.env["pms.availability"]
|
[
|
||||||
.search(
|
("date", "=", record.date),
|
||||||
[
|
("room_id", "=", record.room_id.id),
|
||||||
("room_type_id", "=", record.room_id.room_type_id.id),
|
("id", "!=", record.id),
|
||||||
("date", "=", record.date),
|
("occupies_availability", "=", True),
|
||||||
("pms_property_id", "=", record.pms_property_id.id),
|
]
|
||||||
]
|
):
|
||||||
)
|
|
||||||
.real_avail
|
|
||||||
)
|
|
||||||
if real_avail == 0:
|
|
||||||
record.overbooking = True
|
record.overbooking = True
|
||||||
else:
|
|
||||||
record.overbooking = False
|
|
||||||
else:
|
else:
|
||||||
record.overbooking = False
|
record.overbooking = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user