From 6641e00cd67c5b58c2e558963135afe6d327509f Mon Sep 17 00:00:00 2001 From: atm-adrien <67913809+atm-adrien@users.noreply.github.com> Date: Sat, 19 Jul 2025 00:29:55 +0200 Subject: [PATCH] FIX : Correct rank when adding line on order (#34764) * FIX : Correct rank when adding line on order * FIX : Delete TODO --- htdocs/commande/class/commande.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 3d8a670b693..f261ecea741 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1693,9 +1693,12 @@ class Commande extends CommonOrder if (!empty($fk_parent_line)) { $this->line_order(true, 'DESC'); } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines - $linecount = count($this->lines); - for ($ii = $ranktouse; $ii <= $linecount; $ii++) { - $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1); + foreach ($this->lines as $line) { + if ($line->rang >= $ranktouse) { + if (!empty($line->id)) { + $this->updateRangOfLine($line->id, $line->rang + 1); + } + } } }