Skip to content

Commit

Permalink
[IMP] pms-api-rest: swap reservation lines
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Dec 10, 2021
1 parent 788e56c commit df0ba19
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pms_api_rest/datamodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

from . import pms_checkin_partner_info
from . import pms_partner_info

from . import pms_calendar_swap_info
11 changes: 11 additions & 0 deletions pms_api_rest/datamodels/pms_calendar_swap_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel


class PmsCalendarSwapInfo(Datamodel):
_name = "pms.calendar.swap.info"
swapFrom = fields.String(required=True, allow_none=False)
swapTo = fields.String(required=True, allow_none=False)
roomIdA = fields.Integer(required=True, allow_none=False)
roomIdB = fields.Integer(required=True, allow_none=False)
49 changes: 43 additions & 6 deletions pms_api_rest/services/calendar_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ class PmsCalendarService(Component):
)
def get_calendar(self, calendar_search_param):
domain = list()
domain.append(
("date", ">", datetime.fromisoformat(calendar_search_param.date_from))
)
domain.append(
("date", "<=", datetime.fromisoformat(calendar_search_param.date_to))
)
domain.append(("date", ">=", calendar_search_param.date_from))
domain.append(("date", "<=", calendar_search_param.date_to))
result_lines = []
PmsCalendarInfo = self.env.datamodels["pms.calendar.info"]
for line in (
Expand All @@ -51,3 +47,44 @@ def get_calendar(self, calendar_search_param):
)
)
return result_lines

@restapi.method(
[
(
[
"/swap",
],
"POST",
)
],
input_param=Datamodel("pms.calendar.swap.info", is_list=False),
auth="public",
)
def swap_reservation_slices(self, swap_info):
room_id_a = swap_info.roomIdA
room_id_b = swap_info.roomIdB

lines_room_a = self.env["pms.reservation.line"].search(
[
("room_id", "=", room_id_a),
("date", ">=", swap_info.swapFrom),
("date", "<=", swap_info.swapTo),
]
)

lines_room_b = self.env["pms.reservation.line"].search(
[
("room_id", "=", room_id_b),
("date", ">=", swap_info.swapFrom),
("date", "<=", swap_info.swapTo),
]
)
lines_room_a.occupies_availability = False
lines_room_b.occupies_availability = False
lines_room_a.flush()
lines_room_b.flush()
lines_room_a.room_id = room_id_b
lines_room_b.room_id = room_id_a

lines_room_a._compute_occupies_availability()
lines_room_b._compute_occupies_availability()

0 comments on commit df0ba19

Please sign in to comment.