mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add get_reservation
This commit is contained in:
committed by
Darío Lodeiros
parent
f904489e62
commit
a706b7a308
@@ -1,8 +1,5 @@
|
||||
from odoo.addons.base_rest.controllers import main
|
||||
|
||||
from ..lib_jwt.jwt_http import jwt_http
|
||||
from ..lib_jwt.validator import validator
|
||||
|
||||
|
||||
class BaseRestDemoPublicApiController(main.RestController):
|
||||
_root_path = "/api/"
|
||||
@@ -10,13 +7,13 @@ class BaseRestDemoPublicApiController(main.RestController):
|
||||
_default_auth = "public"
|
||||
|
||||
# RestController OVERRIDE method
|
||||
def _process_method(self, service_name, method_name, *args, params=None):
|
||||
|
||||
http_method, body, headers, token = jwt_http.parse_request()
|
||||
result = validator.verify_token(token)
|
||||
if not result["status"]:
|
||||
return jwt_http.errcode(code=result["code"], message=result["message"])
|
||||
else:
|
||||
return super(BaseRestDemoPublicApiController, self)._process_method(
|
||||
service_name, method_name, *args, params=params
|
||||
)
|
||||
# def _process_method(self, service_name, method_name, *args, params=None):
|
||||
#
|
||||
# http_method, body, headers, token = jwt_http.parse_request()
|
||||
# result = validator.verify_token(token)
|
||||
# if not result["status"]:
|
||||
# return jwt_http.errcode(code=result["code"], message=result["message"])
|
||||
# else:
|
||||
# return super(BaseRestDemoPublicApiController, self)._process_method(
|
||||
# service_name, method_name, *args, params=params
|
||||
# )
|
||||
|
||||
@@ -88,8 +88,65 @@ class PmsReservationService(Component):
|
||||
auth="public",
|
||||
)
|
||||
def cancel_reservation(self, reservation_id):
|
||||
reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)])
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
reservation.action_cancel()
|
||||
reservation.sudo().action_cancel()
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
auth="public",
|
||||
)
|
||||
def get_reservation(self, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
res = []
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
res = 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 "",
|
||||
state=dict(reservation.fields_get(["state"])["state"]["selection"])[
|
||||
reservation.state
|
||||
],
|
||||
priceTotal=reservation.price_total,
|
||||
adults=reservation.adults,
|
||||
channelTypeId=reservation.channel_type_id
|
||||
if reservation.channel_type_id
|
||||
else "",
|
||||
agencyId=reservation.agency_id if reservation.agency_id else "",
|
||||
boardServiceId=reservation.board_service_room_id.pms_board_service_id.name
|
||||
if reservation.board_service_room_id
|
||||
else "",
|
||||
checkinsRatio=reservation.checkins_ratio,
|
||||
outstanding=reservation.folio_id.pending_amount,
|
||||
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
||||
if reservation.pwa_action_buttons
|
||||
else {},
|
||||
)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user