From 1d51394ff9f70607d12bd8d2099566884a5dd43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Wed, 27 May 2026 13:24:59 +0200 Subject: [PATCH 1/2] =?UTF-8?q?A=C3=B1adir=20validaci=C3=B3n=20de=20estado?= =?UTF-8?q?=20del=20documento=20en=20PurchasesController=20y=20SalesContro?= =?UTF-8?q?ller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Se agregó un campo oculto para el estado del documento en CommonSalesPurchases.php. - Se implementó la validación del estado del documento en PurchasesController.php y SalesController.php. - Se añadió un mensaje de advertencia en caso de que el estado del documento cambie. Esto ayuda a prevenir la pérdida de datos al intentar guardar cambios en un documento cuyo estado ha cambiado. --- Core/Lib/AjaxForms/CommonSalesPurchases.php | 1 + Core/Lib/AjaxForms/PurchasesController.php | 8 ++++++++ Core/Lib/AjaxForms/SalesController.php | 8 ++++++++ Core/Translation/es_ES.json | 1 + 4 files changed, 18 insertions(+) diff --git a/Core/Lib/AjaxForms/CommonSalesPurchases.php b/Core/Lib/AjaxForms/CommonSalesPurchases.php index 17e00334cf..0a1d27476f 100644 --- a/Core/Lib/AjaxForms/CommonSalesPurchases.php +++ b/Core/Lib/AjaxForms/CommonSalesPurchases.php @@ -433,6 +433,7 @@ protected static function idestado(TransformerDocument $model, string $jsName): . '' . '' . '' + . '' . ''; } diff --git a/Core/Lib/AjaxForms/PurchasesController.php b/Core/Lib/AjaxForms/PurchasesController.php index dce39d33ee..3cd96dc2bd 100644 --- a/Core/Lib/AjaxForms/PurchasesController.php +++ b/Core/Lib/AjaxForms/PurchasesController.php @@ -375,6 +375,14 @@ protected function saveDocAction(bool $sendOk = true): bool $model = $this->getModel(); $formData = json_decode($this->request->input('data'), true); + + if (isset($formData['idestado']) && (int)$formData['idestado'] !== $model->idestado) { + $this->db()->rollback(); + Tools::log()->warning('document-state-changed'); + $this->sendJsonWithLogs(['ok' => false]); + return false; + } + PurchasesHeaderHTML::apply($model, $formData); PurchasesFooterHTML::apply($model, $formData); diff --git a/Core/Lib/AjaxForms/SalesController.php b/Core/Lib/AjaxForms/SalesController.php index 517c0c8bce..761275d581 100644 --- a/Core/Lib/AjaxForms/SalesController.php +++ b/Core/Lib/AjaxForms/SalesController.php @@ -390,6 +390,14 @@ protected function saveDocAction(bool $sendOk = true): bool $model = $this->getModel(); $formData = json_decode($this->request->input('data'), true); + + if (isset($formData['idestado']) && (int)$formData['idestado'] !== $model->idestado) { + $this->db()->rollback(); + Tools::log()->warning('document-state-changed'); + $this->sendJsonWithLogs(['ok' => false]); + return false; + } + SalesHeaderHTML::apply($model, $formData); SalesFooterHTML::apply($model, $formData); diff --git a/Core/Translation/es_ES.json b/Core/Translation/es_ES.json index a4a84da986..19b43ea04a 100644 --- a/Core/Translation/es_ES.json +++ b/Core/Translation/es_ES.json @@ -480,6 +480,7 @@ "default-retention": "Retención predeterminada", "default-role": "Grupo de usuario pred.", "default-status-non-editable": "El estado predeterminado no es editable", + "document-state-changed": "El estado del documento ha cambiado. Recarga la página antes de guardar.", "default-tax": "Impuesto predeterminado", "default-to-company-email": "Por defecto al email de la empresa", "default-to-config-email": "Por defecto al email de la configuración", From f16e569cac030fc4d58748e838d19aedeccb0621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Wed, 27 May 2026 13:39:41 +0200 Subject: [PATCH 2/2] =?UTF-8?q?A=C3=B1adir=20validaci=C3=B3n=20de=20estado?= =?UTF-8?q?=20del=20documento=20en=20PurchasesController=20y=20SalesContro?= =?UTF-8?q?ller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se ha modificado la lógica de validación en los métodos de guardado de documentos en PurchasesController y SalesController. Ahora se verifica el estado del documento antes de permitir la acción de guardado, asegurando que solo se guarden documentos editables con el estado correcto. - Modificado PurchasesController.php - Modificado SalesController.php --- Core/Lib/AjaxForms/PurchasesController.php | 6 +++++- Core/Lib/AjaxForms/SalesController.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Core/Lib/AjaxForms/PurchasesController.php b/Core/Lib/AjaxForms/PurchasesController.php index 3cd96dc2bd..83c3673b7b 100644 --- a/Core/Lib/AjaxForms/PurchasesController.php +++ b/Core/Lib/AjaxForms/PurchasesController.php @@ -496,7 +496,11 @@ protected function saveStatusAction(): bool return false; } - if ($this->getModel()->editable && false === $this->saveDocAction(false)) { + $formData = json_decode($this->request->input('data'), true); + $currentModel = $this->getModel(); + $formIdestado = isset($formData['idestado']) ? (int)$formData['idestado'] : $currentModel->idestado; + + if ($currentModel->editable && $formIdestado === $currentModel->idestado && false === $this->saveDocAction(false)) { return false; } diff --git a/Core/Lib/AjaxForms/SalesController.php b/Core/Lib/AjaxForms/SalesController.php index 761275d581..b80806cfc1 100644 --- a/Core/Lib/AjaxForms/SalesController.php +++ b/Core/Lib/AjaxForms/SalesController.php @@ -510,7 +510,11 @@ protected function saveStatusAction(): bool return false; } - if ($this->getModel()->editable && false === $this->saveDocAction(false)) { + $formData = json_decode($this->request->input('data'), true); + $currentModel = $this->getModel(); + $formIdestado = isset($formData['idestado']) ? (int)$formData['idestado'] : $currentModel->idestado; + + if ($currentModel->editable && $formIdestado === $currentModel->idestado && false === $this->saveDocAction(false)) { return false; }