From cdaff511478bb5eb28fa9feb03e6b502b9fb3e19 Mon Sep 17 00:00:00 2001 From: Pichinov-Jose Date: Mon, 18 May 2026 01:16:32 +0200 Subject: [PATCH] Fix: FactureFournisseur::addline parameter order in ToolCrudObjects (#38295) Unlike Facture::addline() which takes ($desc, $pu, $qty, $txtva, ...), FactureFournisseur::addline() uses a different parameter order: ($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $remise_percent, ...) i.e. $qty is in position 6, not 3. ToolCrudObjects::processAddLine() was calling FactureFournisseur::addline() with the Facture order, which produced: - our $qty (1) passed as $txtva -> effective VAT rate 1% - our $vat (20) passed as $txlocaltax1 -> wrong local tax - a hardcoded 0 passed as $qty -> the line was inserted with qty=0 and silently dropped from the visible totals The result: every supplier invoice created via create_other_document ended up with the header correctly created but a 0.00 EUR total, with no error returned (lines_added was reported as success). This patch reorders the parameters to match the actual FactureFournisseur::addline() signature and adds an inline comment to warn future maintainers about this Dolibarr API quirk. Other addline calls in the same switch (invoice/order/proposal, supplier_order/supplier_proposal) use their respective correct signatures already and are unaffected. Tested with: create_other_document object_type=supplier_invoice with one line (qty=1, unit_price=10, vat_rate=20) -> line now appears with Total HT 10.00 EUR. --- htdocs/ai/tools/crud_objects.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/htdocs/ai/tools/crud_objects.class.php b/htdocs/ai/tools/crud_objects.class.php index 9b5f25e1fda..61933736148 100644 --- a/htdocs/ai/tools/crud_objects.class.php +++ b/htdocs/ai/tools/crud_objects.class.php @@ -621,7 +621,14 @@ If user says 'order' without any qualifier, they mean a SALES ORDER - use this t $res = $object->addline($desc, $price, $qty, $vat, 0, 0, $fkProduct, $discount, 'HT', 0, 0, $prodType); } elseif ($docType === 'supplier_invoice') { /** @var FactureFournisseur $object */ - $res = $object->addline($desc, $price, $qty, $vat, 0, 0, $fkProduct, $discount, 0, 0, '', 0, 'HT', 0, $prodType); + // IMPORTANT: FactureFournisseur::addline() does NOT share the same signature + // as Facture::addline(). Its parameter order is: + // ($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $remise_percent, ...) + // i.e. $qty is in position 6, not 3 (unlike customer Facture / Commande / Propal). + // The previous call passed our $qty as $txtva (-> a 1% VAT rate) and our $vat + // as $txlocaltax1, and position 6 ended up being a hardcoded 0 -> a line was + // inserted with qty=0, which Dolibarr silently dropped from the visible totals. + $res = $object->addline($desc, $price, $vat, 0, 0, $qty, $fkProduct, $discount, '', '', 0, 0, 'HT', $prodType); } elseif ($docType === 'supplier_order') { /** @var CommandeFournisseur $object */ $res = $object->addline($desc, $price, $qty, $vat, 0, 0, $fkProduct, $discount, 0, 0, 'HT', 0, '', '', $prodType);