From 73d3b8819adda49ed6026c076c6409c0c135dc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sun, 12 May 2024 11:16:49 +0200 Subject: [PATCH] [IMP]pms: improv cancel/confirm prepare vals confirm value in create --- pms/models/pms_reservation.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index cb9d1f1e4..185a4f34d 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -2132,13 +2132,22 @@ class PmsReservation(models.Model): vals["reservation_type"] = ( folio.reservation_type if folio.reservation_type else "normal" ) + # Avoid send state field in vals, with the propouse to + # use action_confirm or action_cancel methods + reservation_state = False + if "state" in vals: + reservation_state = vals["state"] + vals.pop("state") record = super(PmsReservation, self).create(vals) record._check_capacity() - if record.preconfirm and record.state == "draft": + if ( + record.preconfirm and record.state == "draft" + ) or reservation_state == "confirm": record.action_confirm() + elif reservation_state == "cancel": + record.action_cancel() record._check_services(vals) - return record def write(self, vals):