mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[TMP]pms_api_rest: avoid drag&drop change reservation dates
This commit is contained in:
@@ -421,57 +421,67 @@ class PmsCalendarService(Component):
|
||||
def update_reservation(self, reservation_id, reservation_lines_changes):
|
||||
if reservation_lines_changes.reservationLinesChanges:
|
||||
|
||||
# get date of first reservation id to change
|
||||
first_reservation_line_id_to_change = (
|
||||
reservation_lines_changes.reservationLinesChanges[0][
|
||||
"reservationLineId"
|
||||
# TEMP: Disabled temporal date changes to avoid drag&drops errors
|
||||
lines_to_change = self.env["pms.reservation.line"].browse(
|
||||
[
|
||||
item["reservationLineId"]
|
||||
for item in reservation_lines_changes.reservationLinesChanges
|
||||
]
|
||||
)
|
||||
first_reservation_line_to_change = self.env["pms.reservation.line"].browse(
|
||||
first_reservation_line_id_to_change
|
||||
)
|
||||
date_first_reservation_line_to_change = datetime.strptime(
|
||||
reservation_lines_changes.reservationLinesChanges[0]["date"], "%Y-%m-%d"
|
||||
)
|
||||
lines_to_change.room_id = reservation_lines_changes.reservationLinesChanges[
|
||||
0
|
||||
]["roomId"]
|
||||
# # get date of first reservation id to change
|
||||
# first_reservation_line_id_to_change = (
|
||||
# reservation_lines_changes.reservationLinesChanges[0][
|
||||
# "reservationLineId"
|
||||
# ]
|
||||
# )
|
||||
# first_reservation_line_to_change = self.env["pms.reservation.line"].browse(
|
||||
# first_reservation_line_id_to_change
|
||||
# )
|
||||
# date_first_reservation_line_to_change = datetime.strptime(
|
||||
# reservation_lines_changes.reservationLinesChanges[0]["date"], "%Y-%m-%d"
|
||||
# )
|
||||
|
||||
# iterate changes
|
||||
for change_iterator in sorted(
|
||||
reservation_lines_changes.reservationLinesChanges,
|
||||
# adjust order to start changing from last/first reservation line
|
||||
# to avoid reservation line date constraint
|
||||
reverse=first_reservation_line_to_change.date
|
||||
< date_first_reservation_line_to_change.date(),
|
||||
key=lambda x: datetime.strptime(x["date"], "%Y-%m-%d"),
|
||||
):
|
||||
# recordset of each line
|
||||
line_to_change = self.env["pms.reservation.line"].search(
|
||||
[
|
||||
("reservation_id", "=", reservation_id),
|
||||
("id", "=", change_iterator["reservationLineId"]),
|
||||
]
|
||||
)
|
||||
# modifying date, room_id, ...
|
||||
if "date" in change_iterator:
|
||||
line_to_change.date = change_iterator["date"]
|
||||
if (
|
||||
"roomId" in change_iterator
|
||||
and line_to_change.room_id.id != change_iterator["roomId"]
|
||||
):
|
||||
line_to_change.room_id = change_iterator["roomId"]
|
||||
# # iterate changes
|
||||
# for change_iterator in sorted(
|
||||
# reservation_lines_changes.reservationLinesChanges,
|
||||
# # adjust order to start changing from last/first reservation line
|
||||
# # to avoid reservation line date constraint
|
||||
# reverse=first_reservation_line_to_change.date
|
||||
# < date_first_reservation_line_to_change.date(),
|
||||
# key=lambda x: datetime.strptime(x["date"], "%Y-%m-%d"),
|
||||
# ):
|
||||
# # recordset of each line
|
||||
# line_to_change = self.env["pms.reservation.line"].search(
|
||||
# [
|
||||
# ("reservation_id", "=", reservation_id),
|
||||
# ("id", "=", change_iterator["reservationLineId"]),
|
||||
# ]
|
||||
# )
|
||||
# # modifying date, room_id, ...
|
||||
# if "date" in change_iterator:
|
||||
# line_to_change.date = change_iterator["date"]
|
||||
# if (
|
||||
# "roomId" in change_iterator
|
||||
# and line_to_change.room_id.id != change_iterator["roomId"]
|
||||
# ):
|
||||
# line_to_change.room_id = change_iterator["roomId"]
|
||||
|
||||
max_value = max(
|
||||
first_reservation_line_to_change.reservation_id.reservation_line_ids.mapped(
|
||||
"date"
|
||||
)
|
||||
) + timedelta(days=1)
|
||||
min_value = min(
|
||||
first_reservation_line_to_change.reservation_id.reservation_line_ids.mapped(
|
||||
"date"
|
||||
)
|
||||
)
|
||||
reservation = self.env["pms.reservation"].browse(reservation_id)
|
||||
reservation.checkin = min_value
|
||||
reservation.checkout = max_value
|
||||
# max_value = max(
|
||||
# first_reservation_line_to_change.reservation_id.reservation_line_ids.mapped(
|
||||
# "date"
|
||||
# )
|
||||
# ) + timedelta(days=1)
|
||||
# min_value = min(
|
||||
# first_reservation_line_to_change.reservation_id.reservation_line_ids.mapped(
|
||||
# "date"
|
||||
# )
|
||||
# )
|
||||
# reservation = self.env["pms.reservation"].browse(reservation_id)
|
||||
# reservation.checkin = min_value
|
||||
# reservation.checkout = max_value
|
||||
|
||||
else:
|
||||
reservation_to_update = (
|
||||
|
||||
Reference in New Issue
Block a user