mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
109 lines
3.7 KiB
Python
109 lines
3.7 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
from odoo.addons.base_rest import restapi
|
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
|
from odoo.addons.component.core import Component
|
|
|
|
|
|
class PmsCalendarService(Component):
|
|
_inherit = "base.rest.service"
|
|
_name = "pms.private.services"
|
|
_usage = "calendar"
|
|
_collection = "pms.services"
|
|
|
|
@restapi.method(
|
|
[
|
|
(
|
|
[
|
|
"/",
|
|
],
|
|
"GET",
|
|
)
|
|
],
|
|
input_param=Datamodel("pms.calendar.search.param"),
|
|
output_param=Datamodel("pms.calendar.info", is_list=True),
|
|
auth="jwt_api_pms",
|
|
)
|
|
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))
|
|
)
|
|
result_lines = []
|
|
PmsCalendarInfo = self.env.datamodels["pms.calendar.info"]
|
|
for line in (
|
|
self.env["pms.reservation.line"]
|
|
.sudo()
|
|
.search(
|
|
domain,
|
|
)
|
|
):
|
|
result_lines.append(
|
|
PmsCalendarInfo(
|
|
id=line.id,
|
|
state=line.reservation_id.state,
|
|
date=datetime.combine(line.date, datetime.min.time()).isoformat(),
|
|
roomId=line.room_id.id,
|
|
roomTypeName=str(line.reservation_id.room_type_id.default_code),
|
|
toAssign=line.reservation_id.to_assign,
|
|
splitted=line.reservation_id.splitted,
|
|
partnerId=line.reservation_id.partner_id.id or None,
|
|
partnerName=line.reservation_id.partner_name or None,
|
|
reservationId=line.reservation_id,
|
|
reservationName=line.reservation_id.name,
|
|
reservationType=line.reservation_id.reservation_type,
|
|
isFirstDay=line.reservation_id.checkin == line.date,
|
|
isLastDay=line.reservation_id.checkout
|
|
== (line.date + timedelta(days=1)),
|
|
totalPrice=line.reservation_id.price_total,
|
|
pendingPayment=line.reservation_id.folio_pending_amount,
|
|
numNotifications=len(line.reservation_id.message_ids),
|
|
adults=line.reservation_id.adults,
|
|
)
|
|
)
|
|
return result_lines
|
|
|
|
@restapi.method(
|
|
[
|
|
(
|
|
[
|
|
"/swap",
|
|
],
|
|
"POST",
|
|
)
|
|
],
|
|
input_param=Datamodel("pms.calendar.swap.info", is_list=False),
|
|
auth="jwt_api_pms",
|
|
)
|
|
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()
|