diff --git a/pms_api_rest/datamodels/pms_service.py b/pms_api_rest/datamodels/pms_service.py index 0afda50d8..9879e3ddf 100644 --- a/pms_api_rest/datamodels/pms_service.py +++ b/pms_api_rest/datamodels/pms_service.py @@ -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) diff --git a/pms_api_rest/services/pms_reservation_service.py b/pms_api_rest/services/pms_reservation_service.py index f69d7b013..593031f18 100644 --- a/pms_api_rest/services/pms_reservation_service.py +++ b/pms_api_rest/services/pms_reservation_service.py @@ -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( + [ + ( + [ + "//reservation-lines/", + ], + "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): [ ( [ - "//reservation-lines/", + "//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( [ diff --git a/pms_api_rest/services/pms_service_service.py b/pms_api_rest/services/pms_service_service.py index 38ab9a5ec..7ba5c60d8 100644 --- a/pms_api_rest/services/pms_service_service.py +++ b/pms_api_rest/services/pms_service_service.py @@ -14,6 +14,36 @@ class PmsServiceService(Component): _usage = "services" _collection = "pms.services" + @restapi.method( + [ + ( + [ + "/", + ], + "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( [ (