FIX out of dynamically recalculated unit price inc tax was missing

relative discount.
This commit is contained in:
Laurent Destailleur 2026-05-23 01:33:38 +02:00
parent 228da2b7b7
commit a2eadd7ed0
2 changed files with 10 additions and 5 deletions

View file

@ -2212,10 +2212,10 @@ class Commande extends CommonOrder
$this->lines = array();
$sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.vat_src_code, l.tva_tx, l.ref_ext,';
$sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.fk_remise_except, l.remise_percent, l.subprice, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.rang, l.info_bits, l.special_code,';
$sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.fk_remise_except, l.remise_percent, l.subprice, l.subprice_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.rang, l.info_bits, l.special_code,';
$sql .= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,';
$sql .= ' l.fk_unit, l.extraparams,';
$sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
$sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_subprice_ttc, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
$sql .= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch, p.barcode as product_barcode,';
$sql .= ' p.customcode, p.fk_country as country_id, c.code as country_code,';
$sql .= ' p.weight, p.weight_units, p.volume, p.volume_units, p.packaging';
@ -2262,6 +2262,7 @@ class Commande extends CommonOrder
$line->total_localtax1 = $objp->total_localtax1;
$line->total_localtax2 = $objp->total_localtax2;
$line->subprice = $objp->subprice;
$line->subprice_ttc = $objp->subprice_ttc;
$line->fk_remise_except = $objp->fk_remise_except;
$line->remise_percent = $objp->remise_percent;
$line->price = $objp->price;
@ -2308,6 +2309,7 @@ class Commande extends CommonOrder
$line->fk_multicurrency = $objp->fk_multicurrency;
$line->multicurrency_code = $objp->multicurrency_code;
$line->multicurrency_subprice = $objp->multicurrency_subprice;
$line->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
$line->multicurrency_total_ht = $objp->multicurrency_total_ht;
$line->multicurrency_total_tva = $objp->multicurrency_total_tva;
$line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;

View file

@ -5610,9 +5610,12 @@ abstract class CommonObject
// Recalculate unit price with tax if not defined
if (empty($line->subprice_ttc) && $line->qty) { // subprice_ttc may be not stored on old version or not defined for lines with no unit price (like a discount)
// So we calculate an estimated value just to show something on screen
$line->subprice_ttc = (float) price2num($line->total_ttc / $line->qty * (1 - $line->remise_percent / 100), 'MU');
//other method is less accurate
// $line->subprice_ttc = (float) price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)), 'MU');
if ($line->remise_percent != 100) {
$line->subprice_ttc = (float) price2num($line->total_ttc / $line->qty / (1 - $line->remise_percent / 100), 'MU');
} else {
// Other method is less accurate
$line->subprice_ttc = (float) price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)), 'MU');
}
}
$line->pu_ttc = $line->subprice_ttc; // deprecated