mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP]pms_api_rest: POST services reservation
This commit is contained in:
@@ -7,6 +7,7 @@ class PmsServiceInfo(Datamodel):
|
||||
_name = "pms.service.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
productId = fields.Integer(required=True, allow_none=False)
|
||||
quantity = fields.Integer(required=False, allow_none=True)
|
||||
priceTotal = fields.Float(required=False, allow_none=True)
|
||||
priceSubtotal = fields.Float(required=False, allow_none=True)
|
||||
|
||||
@@ -14,6 +14,10 @@ class PmsReservationService(Component):
|
||||
_usage = "reservations"
|
||||
_collection = "pms.services"
|
||||
|
||||
# ------------------------------------------------------------------------------------
|
||||
# HEAD RESERVATION--------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
@@ -213,6 +217,10 @@ class PmsReservationService(Component):
|
||||
)
|
||||
reservation_to_update.write(reservation_vals)
|
||||
|
||||
# ------------------------------------------------------------------------------------
|
||||
# RESERVATION LINES-------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
@@ -299,13 +307,40 @@ class PmsReservationService(Component):
|
||||
line = reservation.reservation_line_ids.filtered(lambda l: l.id == reservation_line_id)
|
||||
if (
|
||||
line
|
||||
and line.date > min(reservation.reservation_line_ids.mapped("date"))
|
||||
and line.date < max(reservation.reservation_line_ids.mapped("date"))
|
||||
and (
|
||||
line.date == min(reservation.reservation_line_ids.mapped("date"))
|
||||
or line.date == max(reservation.reservation_line_ids.mapped("date"))
|
||||
)
|
||||
):
|
||||
line.unlink()
|
||||
else:
|
||||
raise MissingError(_("It was not possible to remove the reservation line"))
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:_reservation_id>/reservation-lines/<int:reservation_line_id>",
|
||||
],
|
||||
"PATCH",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.reservation.line.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def update_reservation_lines(
|
||||
self, _reservation_id, reservation_line_id, reservation_line_param
|
||||
):
|
||||
if reservation_line_param.roomId:
|
||||
reservation_line_id = self.env["pms.reservation.line"].browse(
|
||||
reservation_line_id
|
||||
)
|
||||
reservation_line_id.room_id = reservation_line_param.roomId
|
||||
|
||||
# ------------------------------------------------------------------------------------
|
||||
# RESERVATION SERVICES----------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
@@ -329,6 +364,7 @@ class PmsReservationService(Component):
|
||||
PmsServiceInfo(
|
||||
id=service.id,
|
||||
name=service.name,
|
||||
productId=service.product_id.id,
|
||||
quantity=service.product_qty,
|
||||
priceTotal=round(service.price_total, 2),
|
||||
priceSubtotal=round(service.price_subtotal, 2),
|
||||
@@ -343,22 +379,28 @@ class PmsReservationService(Component):
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:_reservation_id>/reservation-lines/<int:reservation_line_id>",
|
||||
"/<int:reservation_id>/services",
|
||||
],
|
||||
"PATCH",
|
||||
"POST",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.reservation.line.info", is_list=False),
|
||||
input_param=Datamodel("pms.service.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def update_reservation_lines(
|
||||
self, _reservation_id, reservation_line_id, reservation_line_param
|
||||
):
|
||||
if reservation_line_param.roomId:
|
||||
reservation_line_id = self.env["pms.reservation.line"].browse(
|
||||
reservation_line_id
|
||||
)
|
||||
reservation_line_id.room_id = reservation_line_param.roomId
|
||||
def create_reservation_service(self, reservation_id, service_info):
|
||||
reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)])
|
||||
if not reservation:
|
||||
raise MissingError(_("Reservation not found"))
|
||||
vals = {
|
||||
"product_id": service_info.quantity,
|
||||
"reservation_id": reservation.id,
|
||||
}
|
||||
service = self.env["pms.service"].create(vals)
|
||||
return service.id
|
||||
|
||||
# ------------------------------------------------------------------------------------
|
||||
# RESERVATION CHECKINS----------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
|
||||
@@ -14,6 +14,36 @@ class PmsServiceService(Component):
|
||||
_usage = "services"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:service_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.service.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_service(self, service_id):
|
||||
service = self.env["pms.service"].search([("id", "=", service_id)])
|
||||
if not service:
|
||||
raise MissingError(_("Service not found"))
|
||||
PmsServiceInfo = self.env.datamodels["pms.service.info"]
|
||||
|
||||
return PmsServiceInfo(
|
||||
id=service.id,
|
||||
name=service.name,
|
||||
productId=service.product_id.id,
|
||||
quantity=service.product_qty,
|
||||
priceTotal=round(service.price_total, 2),
|
||||
priceSubtotal=round(service.price_subtotal, 2),
|
||||
priceTaxes=round(service.price_tax, 2),
|
||||
discount=round(service.discount, 2),
|
||||
isBoardService=service.is_board_service,
|
||||
)
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user