diff --git a/pms_api_rest/datamodels/__init__.py b/pms_api_rest/datamodels/__init__.py index fd0bf8e53d..155aaec3e2 100644 --- a/pms_api_rest/datamodels/__init__.py +++ b/pms_api_rest/datamodels/__init__.py @@ -12,3 +12,5 @@ from . import pms_checkin_partner_info from . import pms_partner_info + +from . import pms_calendar_swap_info diff --git a/pms_api_rest/datamodels/pms_calendar_swap_info.py b/pms_api_rest/datamodels/pms_calendar_swap_info.py new file mode 100644 index 0000000000..ee9f2a0bb0 --- /dev/null +++ b/pms_api_rest/datamodels/pms_calendar_swap_info.py @@ -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) diff --git a/pms_api_rest/services/calendar_service.py b/pms_api_rest/services/calendar_service.py index 7a0d36e147..b33660dbf5 100644 --- a/pms_api_rest/services/calendar_service.py +++ b/pms_api_rest/services/calendar_service.py @@ -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 ( @@ -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()