* Fix #34069 read shipping weight, dimensions and quantities as floats htdocs/expedition/card.php read the package weight, the three box dimensions (sizeH / sizeW / sizeS), the true* fields (trueWeight / trueWidth / trueHeight / trueDepth) and the per-line shipped quantity with GETPOSTINT(). All of these are physical quantities that routinely use decimals (a 1.6 kg parcel, a 0.25 m box edge, a 0.5 unit of service), and GETPOSTINT() silently truncates the fractional part so a 1.6 kg weight was stored as 1 kg and a 0.25 line quantity was stored as 0, breaking the link with the source order line. The reporter ran into both cases on v20 and confirmed it is still present on v22. Replace the GETPOSTINT() reads with GETPOST() + price2num() casts at the six save sites (the initial create from source order, the four 'settrueX' inline actions and the per-line qtyl input) and the displayed weight value, mirroring the float handling that exists in htdocs/commande/card.php and other places. The weight unit and size unit dropdowns stay as GETPOSTINT() since those are dictionary ids. Same code path on 21.0, 22.0, 23.0 and develop; PR targets 21.0. Signed-off-by: Dolicraft <contact@dolicraft.com> * Fix #34069 use GETPOSTFLOAT helper per review Address @eldy review on PR #38549: the develop branch already uses GETPOSTFLOAT() at the same call sites, so backport the helper to v21 instead of inlining (float) price2num(GETPOST(...)). Same semantics (GETPOSTFLOAT wraps the same expression at functions.lib.php line 1152 on 21.0) but shorter and idiomatic with the rest of the codebase. Signed-off-by: Dolicraft <contact@dolicraft.com> --------- Signed-off-by: Dolicraft <contact@dolicraft.com> Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
parent
c01f807b44
commit
28999e5486
1 changed files with 14 additions and 11 deletions
|
|
@ -251,10 +251,13 @@ if (empty($reshook)) {
|
|||
$object->origin = $origin;
|
||||
$object->origin_id = $origin_id;
|
||||
$object->fk_project = GETPOSTINT('projectid');
|
||||
$object->weight = GETPOSTINT('weight') == '' ? "NULL" : GETPOSTINT('weight');
|
||||
$object->sizeH = GETPOSTINT('sizeH') == '' ? "NULL" : GETPOSTINT('sizeH');
|
||||
$object->sizeW = GETPOSTINT('sizeW') == '' ? "NULL" : GETPOSTINT('sizeW');
|
||||
$object->sizeS = GETPOSTINT('sizeS') == '' ? "NULL" : GETPOSTINT('sizeS');
|
||||
// Weight and box dimensions are physical measurements that frequently use
|
||||
// decimals (1.6 kg, 0.25 m, ...), so they must be read as floats and not
|
||||
// truncated to int (see issue #34069 for the shipping module).
|
||||
$object->weight = GETPOST('weight', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('weight');
|
||||
$object->sizeH = GETPOST('sizeH', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('sizeH');
|
||||
$object->sizeW = GETPOST('sizeW', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('sizeW');
|
||||
$object->sizeS = GETPOST('sizeS', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('sizeS');
|
||||
$object->size_units = GETPOSTINT('size_units');
|
||||
$object->weight_units = GETPOSTINT('weight_units');
|
||||
|
||||
|
|
@ -579,18 +582,18 @@ if (empty($reshook)) {
|
|||
$object->tracking_url = trim(GETPOST('tracking_url', 'restricthtml'));
|
||||
}
|
||||
if ($action == 'settrueWeight') {
|
||||
$object->trueWeight = GETPOSTINT('trueWeight');
|
||||
$object->trueWeight = GETPOSTFLOAT('trueWeight');
|
||||
$object->weight_units = GETPOSTINT('weight_units');
|
||||
}
|
||||
if ($action == 'settrueWidth') {
|
||||
$object->trueWidth = GETPOSTINT('trueWidth');
|
||||
$object->trueWidth = GETPOSTFLOAT('trueWidth');
|
||||
}
|
||||
if ($action == 'settrueHeight') {
|
||||
$object->trueHeight = GETPOSTINT('trueHeight');
|
||||
$object->trueHeight = GETPOSTFLOAT('trueHeight');
|
||||
$object->size_units = GETPOSTINT('size_units');
|
||||
}
|
||||
if ($action == 'settrueDepth') {
|
||||
$object->trueDepth = GETPOSTINT('trueDepth');
|
||||
$object->trueDepth = GETPOSTFLOAT('trueDepth');
|
||||
}
|
||||
if ($action == 'setshipping_method_id') {
|
||||
$object->shipping_method_id = GETPOSTINT('shipping_method_id');
|
||||
|
|
@ -1080,7 +1083,7 @@ if ($action == 'create') {
|
|||
print $langs->trans("Weight");
|
||||
print '</td><td colspan="3">';
|
||||
print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');
|
||||
print '<input name="weight" size="4" value="'.GETPOSTINT('weight').'"> ';
|
||||
print '<input name="weight" size="4" value="'.dol_escape_htmltag(GETPOST('weight', 'alpha')).'"> ';
|
||||
$text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTINT('weight_units'), 0, 2);
|
||||
$htmltext = $langs->trans("KeepEmptyForAutoCalculation");
|
||||
print $form->textwithpicto($text, $htmltext);
|
||||
|
|
@ -1357,8 +1360,8 @@ if ($action == 'create') {
|
|||
// Quantity to send
|
||||
print '<td class="center">';
|
||||
if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || ($line->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES'))) {
|
||||
if (GETPOSTINT('qtyl'.$indiceAsked)) {
|
||||
$deliverableQty = GETPOSTINT('qtyl'.$indiceAsked);
|
||||
if (GETPOSTISSET('qtyl'.$indiceAsked) && GETPOST('qtyl'.$indiceAsked) !== '') {
|
||||
$deliverableQty = GETPOSTFLOAT('qtyl'.$indiceAsked, 'MS');
|
||||
}
|
||||
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
|
||||
print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" class="qtyl right" type="text" size="4" value="'.$deliverableQty.'">';
|
||||
|
|
|
|||
Loading…
Reference in a new issue