From 639e7fe10ba5603bd94f398ec392f98a0eea4a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Wed, 13 Jul 2022 17:03:11 +0200 Subject: [PATCH] [FIX]pms_api_rest: Add DELETE reservation line service --- .../services/pms_reservation_line_service.py | 2 +- .../services/pms_reservation_service.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pms_api_rest/services/pms_reservation_line_service.py b/pms_api_rest/services/pms_reservation_line_service.py index ac05932c3..411f41900 100644 --- a/pms_api_rest/services/pms_reservation_line_service.py +++ b/pms_api_rest/services/pms_reservation_line_service.py @@ -10,7 +10,7 @@ from odoo.addons.component.core import Component class PmsReservationLineService(Component): _inherit = "base.rest.service" - _name = "pms.reservation.line.service" + _name = "pms.reservationline.service" _usage = "reservation-lines" _collection = "pms.services" diff --git a/pms_api_rest/services/pms_reservation_service.py b/pms_api_rest/services/pms_reservation_service.py index 37b038e46..c37348086 100644 --- a/pms_api_rest/services/pms_reservation_service.py +++ b/pms_api_rest/services/pms_reservation_service.py @@ -248,6 +248,30 @@ class PmsReservationService(Component): ) return result_lines + @restapi.method( + [ + ( + [ + "//reservation-lines/", + ], + "DELETE", + ) + ], + auth="jwt_api_pms", + ) + def delete_reservation_line(self, reservation_id, reservation_line_id): + reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)]) + line = reservation.reservation_line_ids.filtered(lambda l: l.id == reservation_line_id) + if ( + line + and len(reservation.reservation_line_ids) == 1 + and line.date > min(reservation.reservation_line_ids.mapped("date")) + and 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( [ (