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..83c3673b7b 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); @@ -488,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 517c0c8bce..b80806cfc1 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); @@ -502,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; } 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",