Fix #38320 treat null/empty rang as auto in addline (Propal, Commande, Facture) (#38843)

API callers like api_proposals.php postLine forward $request_data->rang
unset, so null reaches addline. The '== -1' check does not match null and
$ranktouse stays null, persisted as 0 - all lines then share rang=0 and
the order propagates through createFromProposal / createFromOrder.

Accept null and 0 alongside -1 so the auto-rank branch fires.

Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
w3houde 2026-06-16 02:07:48 +02:00 committed by GitHub
parent ae99530e25
commit 35db492be1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -783,7 +783,7 @@ class Propal extends CommonObject
// Rang to use
$ranktouse = $rang;
if ($ranktouse == -1) {
if (empty($ranktouse) || $ranktouse == -1) {
$rangmax = $this->line_max($fk_parent_line);
$ranktouse = $rangmax + 1;
}

View file

@ -1763,7 +1763,7 @@ class Commande extends CommonOrder
// Rang to use
$ranktouse = $rang;
if ($ranktouse == -1) {
if (empty($ranktouse) || $ranktouse == -1) {
$rangmax = $this->line_max($fk_parent_line);
$ranktouse = $rangmax + 1;
}

View file

@ -4397,7 +4397,7 @@ class Facture extends CommonInvoice
// Rank to use
$ranktouse = $rang;
if ($ranktouse == -1) {
if (empty($ranktouse) || $ranktouse == -1) {
$rangmax = $this->line_max($fk_parent_line);
$ranktouse = $rangmax + 1;
}