From 7e723042719c1925bdc376b4bcd16920e3d11aac Mon Sep 17 00:00:00 2001 From: support-accellier <151022268+support-accellier@users.noreply.github.com> Date: Thu, 13 Aug 2026 07:29:28 +0530 Subject: [PATCH] FIX #39425 Missing rollback when stock movement fails in Expedition::valid() (#39426) * Fix missing rollback when stock movement fails in Expedition::valid() When STOCK_CALCULATE_ON_SHIPMENT is enabled and manageStockMvtOnEvt() fails while validating a shipment, the method returned -2 directly without calling $this->db->rollback(), unlike every other error branch in this method. Changed to increment $error instead, so execution falls through to the existing commit/rollback block at the end of valid(). Fixes #39425 * Update expedition.class.php --------- Co-authored-by: Laurent Destailleur --- htdocs/expedition/class/expedition.class.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 13c9d1ab13b..c47bd711e3e 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1058,7 +1058,7 @@ class Expedition extends CommonObject if (!$error && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) { $result = $this->manageStockMvtOnEvt($user, "ShipmentValidatedInDolibarr"); if ($result < 0) { - return -2; + $error++; } } @@ -1071,9 +1071,11 @@ class Expedition extends CommonObject } // TODO : load the origin object to trigger the right setStatus according to origin object - $ret = $this->setStatut(Commande::STATUS_SHIPMENTONPROCESS, $this->origin_id, $this->origin, $triggerKey); - if (!$ret) { - $error++; + if (!$error) { + $ret = $this->setStatut(Commande::STATUS_SHIPMENTONPROCESS, $this->origin_id, $this->origin, $triggerKey); + if (!$ret) { + $error++; + } } if (!$error && !$notrigger) {