Skip to content

Commit

Permalink
[IMP]pms: improvement compute overbooking and boardservices
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Apr 22, 2024
1 parent 048f33a commit e415b81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pms/models/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ def action_open_mail_composer(self, ctx, res_id=False, res_ids=False):
}

def _message_post_after_hook(self, message, msg_vals):
res = super(PmsFolio, self).sudo()._message_post_after_hook(message, msg_vals)
res = super(PmsFolio, self)._message_post_after_hook(message, msg_vals)
for folio in self:
for follower in folio.message_follower_ids:
follower.sudo().unlink()
Expand Down
28 changes: 25 additions & 3 deletions pms/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,14 @@ def _compute_service_ids(self):
if (reservation.adults and line.adults) or (
reservation.children and line.children
):
res = {
data = {
"product_id": line.product_id.id,
"is_board_service": True,
"folio_id": reservation.folio_id.id,
"reservation_id": reservation.id,
"board_service_line_id": line.id,
}
board_services.append((0, False, res))
board_services.append((0, False, data))
reservation.service_ids -= old_board_lines
reservation.service_ids = board_services
elif old_board_lines:
Expand Down Expand Up @@ -2153,7 +2153,29 @@ def write(self, vals):
vals.get("reservation_line_ids")
and any(
[
("date" in line[2] or "price" in line[2])
(
"date" in line[2]
and (
datetime.datetime.strptime(
line[2]["date"], "%Y-%m-%d"
).date()
!= self.env["pms.reservation.line"]
.browse(line[1])
.date
)
)
or (
"price" in line[2]
and (
round(line[2]["price"], 2)
!= round(
self.env["pms.reservation.line"]
.browse(line[1])
.price,
2,
)
)
)
for line in vals.get("reservation_line_ids")
if line[0] == 1
]
Expand Down
13 changes: 8 additions & 5 deletions pms/models/pms_reservation_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def _compute_avail_id(self):
).ids
if (
record.occupies_availability
and not self.env.context.get("avoid_availability_check", False)
and not (
self.env.context.get("avoid_availability_check", False)
or self.env.context.get("force_overbooking", False)
)
and record.room_id.id
in avail.get_rooms_not_avail(
checkin=record.date,
Expand Down Expand Up @@ -475,10 +478,10 @@ def _compute_price_day_total(self):
discount = first_discount + cancel_discount
line.price_day_total = line.price - discount

@api.depends("room_id", "avail_id", "avail_id.real_avail", "occupies_availability")
@api.depends("room_id", "state", "is_reselling")
def _compute_overbooking(self):
for record in self.filtered("room_id"):
if record.occupies_availability:
if record.state != "cancel" and not record.is_reselling:
record_id = (
record.id
if isinstance(record, int)
Expand All @@ -495,8 +498,8 @@ def _compute_overbooking(self):
]
):
record.overbooking = True
else:
record.overbooking = False
else:
record.overbooking = False

@api.model_create_multi
def create(self, vals_list):
Expand Down
4 changes: 4 additions & 0 deletions pms/views/pms_reservation_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@
widget="many2many_tags"
optional="show"
/>
<field
name="board_service_line_id"
invisible="1"
/>
<field name="price_subtotal" optional="hide" />
<field name="price_tax" optional="hide" />
<field name="discount" />
Expand Down

0 comments on commit e415b81

Please sign in to comment.