mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import json
|
|
|
|
from odoo.addons.base_rest import restapi
|
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
|
from odoo.addons.component.core import Component
|
|
|
|
|
|
class PmsReservationService(Component):
|
|
_inherit = "base.rest.service"
|
|
_name = "pms.reservation.service"
|
|
_usage = "reservations"
|
|
_collection = "pms.reservation.service"
|
|
|
|
@restapi.method(
|
|
[
|
|
(
|
|
[
|
|
"/",
|
|
],
|
|
"GET",
|
|
)
|
|
],
|
|
input_param=Datamodel("pms.reservation.search.param"),
|
|
output_param=Datamodel("pms.reservation.short.info", is_list=True),
|
|
auth="public",
|
|
)
|
|
def search(self, reservation_search_param):
|
|
domain = []
|
|
if reservation_search_param.name:
|
|
domain.append(("name", "like", reservation_search_param.name))
|
|
if reservation_search_param.id:
|
|
domain.append(("id", "=", reservation_search_param.id))
|
|
res = []
|
|
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
|
for reservation in (
|
|
self.env["pms.reservation"]
|
|
.sudo()
|
|
.search(
|
|
domain,
|
|
)
|
|
):
|
|
res.append(
|
|
PmsReservationShortInfo(
|
|
id=reservation.id,
|
|
partner=reservation.partner_id.name,
|
|
checkin=str(reservation.checkin),
|
|
checkout=str(reservation.checkout),
|
|
preferredRoomId=reservation.preferred_room_id.name
|
|
if reservation.preferred_room_id
|
|
else "",
|
|
roomTypeId=reservation.room_type_id.name
|
|
if reservation.room_type_id
|
|
else "",
|
|
name=reservation.name,
|
|
partnerRequests=reservation.partner_requests
|
|
if reservation.partner_requests
|
|
else "",
|
|
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
|
if reservation.pwa_action_buttons
|
|
else {},
|
|
)
|
|
)
|
|
return res
|