mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: imrpovemente performance issues on folio sale lines compute
This commit is contained in:
@@ -796,13 +796,14 @@ class PmsFolio(models.Model):
|
||||
"reservation_ids.tax_ids",
|
||||
)
|
||||
def _compute_sale_line_ids(self):
|
||||
for folio in self:
|
||||
for folio in self.filtered(lambda f: isinstance(f.id, int)):
|
||||
sale_lines_vals = []
|
||||
if folio.reservation_type == "normal":
|
||||
sale_lines_vals_to_drop = []
|
||||
seq = 0
|
||||
for reservation in sorted(
|
||||
folio.reservation_ids, key=lambda r: r.folio_sequence
|
||||
folio.reservation_ids.filtered(lambda r: isinstance(r.id, int)),
|
||||
key=lambda r: r.folio_sequence,
|
||||
):
|
||||
seq += reservation.folio_sequence
|
||||
# RESERVATION LINES
|
||||
|
||||
@@ -23,6 +23,7 @@ class PmsReservationLine(models.Model):
|
||||
copy=False,
|
||||
comodel_name="pms.reservation",
|
||||
ondelete="cascade",
|
||||
index=True,
|
||||
check_pms_properties=True,
|
||||
)
|
||||
room_id = fields.Many2one(
|
||||
|
||||
@@ -250,24 +250,33 @@ class BookingEngine(models.TransientModel):
|
||||
)
|
||||
else:
|
||||
folio = record.folio_id
|
||||
reservation_values = []
|
||||
for line in record.availability_results:
|
||||
for _reservations_to_create in range(0, line.value_num_rooms_selected):
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"folio_id": folio.id,
|
||||
"checkin": line.checkin,
|
||||
"checkout": line.checkout,
|
||||
"room_type_id": line.room_type_id.id,
|
||||
"partner_id": record.partner_id.id
|
||||
if record.partner_id
|
||||
else False,
|
||||
"partner_name": record.partner_name,
|
||||
"pricelist_id": record.pricelist_id.id,
|
||||
"pms_property_id": folio.pms_property_id.id,
|
||||
"board_service_room_id": line.board_service_room_id.id,
|
||||
}
|
||||
)
|
||||
res.reservation_line_ids.discount = record.discount * 100
|
||||
res_dict = {
|
||||
"folio_id": folio.id,
|
||||
"checkin": line.checkin,
|
||||
"checkout": line.checkout,
|
||||
"room_type_id": line.room_type_id.id,
|
||||
"partner_id": record.partner_id.id
|
||||
if record.partner_id
|
||||
else False,
|
||||
"partner_name": record.partner_name,
|
||||
"pricelist_id": record.pricelist_id.id,
|
||||
"pms_property_id": folio.pms_property_id.id,
|
||||
"board_service_room_id": line.board_service_room_id.id,
|
||||
}
|
||||
reservation_values.append((0, 0, res_dict))
|
||||
folio.write(
|
||||
{
|
||||
"reservation_ids": reservation_values,
|
||||
}
|
||||
)
|
||||
if record.discount:
|
||||
# TODO: Refact compute discount in reservation and service lines
|
||||
folio.reservation_ids.reservation_line_ids.discount = (
|
||||
record.discount * 100
|
||||
)
|
||||
action = self.env.ref("pms.open_pms_folio1_form_tree_all").read()[0]
|
||||
action["views"] = [(self.env.ref("pms.pms_folio_view_form").id, "form")]
|
||||
action["res_id"] = folio.id
|
||||
|
||||
Reference in New Issue
Block a user