Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/Lib/AjaxForms/CommonSalesPurchases.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ protected static function idestado(TransformerDocument $model, string $jsName):
. '<div class="dropdown-menu dropdown-menu-right">' . implode('', $options) . '</div>'
. '</div>'
. '</div>'
. '<input type="hidden" name="idestado" value="' . $model->idestado . '">'
. '</div>';
}

Expand Down
14 changes: 13 additions & 1 deletion Core/Lib/AjaxForms/PurchasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 13 additions & 1 deletion Core/Lib/AjaxForms/SalesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions Core/Translation/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down