diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php
index 0a31bb79408..20889e1a742 100644
--- a/htdocs/core/class/commondocgenerator.class.php
+++ b/htdocs/core/class/commondocgenerator.class.php
@@ -643,11 +643,11 @@ abstract class CommonDocGenerator
$array_key.'_tracking_number'=>$object->tracking_number,
$array_key.'_tracking_url'=>$object->tracking_url,
$array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
- $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'),
- $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'),
- $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'),
- $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'),
- $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'),
+ $array_key.'_weight'=>$object->trueWeight.' '.measuringUnitString(0, 'weight', $object->weight_units),
+ $array_key.'_width'=>$object->trueWidth.' '.measuringUnitString(0, 'size', $object->width_units),
+ $array_key.'_height'=>$object->trueHeight.' '.measuringUnitString(0, 'size', $object->height_units),
+ $array_key.'_depth'=>$object->trueDepth.' '.measuringUnitString(0, 'size', $object->depth_units),
+ $array_key.'_size'=>$calculatedVolume.' '.measuringUnitString(0, 'volume'),
);
// Add vat by rates
@@ -701,10 +701,10 @@ abstract class CommonDocGenerator
'line_price_ht'=>price($line->total_ht),
'line_price_ttc'=>price($line->total_ttc),
'line_price_vat'=>price($line->total_tva),
- 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'),
- 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'),
- 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'),
- 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'),
+ 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuringUnitString(0, 'weight', $line->weight_units),
+ 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuringUnitString(0, 'size', $line->length_units),
+ 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuringUnitString(0, 'surface', $line->surface_units),
+ 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuringUnitString(0, 'volume', $line->volume_units),
);
// Retrieve extrafields
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 838670b58c0..b331c479670 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -3823,17 +3823,18 @@ abstract class CommonObject
$totalWeight += $weight * $qty * $trueWeightUnit;
}
else {
- if ($weight_units == 99) {
- // conversion 1 Pound = 0.45359237 KG
- $trueWeightUnit = 0.45359237;
- $totalWeight += $weight * $qty * $trueWeightUnit;
- } elseif ($weight_units == 98) {
- // conversion 1 Ounce = 0.0283495 KG
- $trueWeightUnit = 0.0283495;
- $totalWeight += $weight * $qty * $trueWeightUnit;
- }
- else
+ if ($weight_units == 99) {
+ // conversion 1 Pound = 0.45359237 KG
+ $trueWeightUnit = 0.45359237;
+ $totalWeight += $weight * $qty * $trueWeightUnit;
+ } elseif ($weight_units == 98) {
+ // conversion 1 Ounce = 0.0283495 KG
+ $trueWeightUnit = 0.0283495;
+ $totalWeight += $weight * $qty * $trueWeightUnit;
+ }
+ else {
$totalWeight += $weight * $qty; // This may be wrong if we mix different units
+ }
}
if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
{
diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php
index 07cd778d3a0..e37849ff99a 100644
--- a/htdocs/core/class/cunits.class.php
+++ b/htdocs/core/class/cunits.class.php
@@ -247,8 +247,8 @@ class CUnits // extends CommonObject
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
- if ($key=='t.rowid' || $key=='t.active') {
- $sqlwhere[] = $key . '='. $value;
+ if ($key=='t.rowid' || $key=='t.active' || $key=='t.scale') {
+ $sqlwhere[] = $key . '='. (int) $value;
}
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index b4c52117ea9..cc6cdb78790 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -2425,7 +2425,7 @@ class Form
$outvalUnits .= ' - ' . $unitToShow;
}
if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units!==null) {
- $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuring_units_string($objp->length_units, 'size');
+ $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuringUnitString(0, 'size', $objp->length_units);
$outvalUnits .= ' - ' . $unitToShow;
}
if (!empty($objp->surface) && $objp->surface_units!==null) {
@@ -2802,7 +2802,7 @@ class Form
$outvalUnits .= ' - ' . $unitToShow;
}
if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units!==null) {
- $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuring_units_string($objp->length_units, 'size');
+ $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuringUnitString(0, 'size', $objp->length_units);
$outvalUnits .= ' - ' . $unitToShow;
}
if (!empty($objp->surface) && $objp->surface_units!==null) {
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 88c20a2aaa8..09b184ad349 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4624,7 +4624,7 @@ function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round
$unit = $forceunitoutput;
}*/
- $ret=price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuring_units_string(0, $type, $unit);
+ $ret=price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuringUnitString(0, $type, $unit);
return $ret;
}
diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php
index 170421cecfd..2a2ee90493b 100644
--- a/htdocs/core/lib/product.lib.php
+++ b/htdocs/core/lib/product.lib.php
@@ -479,6 +479,22 @@ function show_stats_for_company($product, $socid)
return $nblines++;
}
+/**
+ * Return translation label of a unit key.
+ * Function kept for backward compatibility.
+ *
+ * @param string $scale Scale of unit: '0', '-3', '6', ...
+ * @param string $measuring_style Style of unit: weight, volume,...
+ * @param int $unit ID of unit (rowid in llx_c_units table)
+ * @param int $use_short_label 1=Use short label ('g' instead of 'gram'). Short labels are not translated.
+ * @return string Unit string
+ * @see formproduct->selectMeasuringUnits
+ */
+function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $use_short_label = 0)
+{
+ return measuringUnitString($unit, $measuring_style, $scale, $use_short_label);
+}
+
/**
* Return translation label of a unit key
*
@@ -489,7 +505,7 @@ function show_stats_for_company($product, $socid)
* @return string Unit string
* @see formproduct->selectMeasuringUnits
*/
-function measuring_units_string($unit, $measuring_style = '', $scale = '', $use_short_label = 0)
+function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0)
{
global $langs, $db;
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
diff --git a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
index 21658ed32d0..9235cddc90f 100644
--- a/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
+++ b/htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
@@ -509,12 +509,12 @@ class pdf_espadon extends ModelePdfExpedition
$weighttxt='';
if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
{
- $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units, "weight");
+ $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units);
}
$voltxt='';
if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
{
- $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0, "volume");
+ $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0);
}
diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
index b180994b7e5..7757e3c9b56 100644
--- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
+++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
@@ -525,12 +525,12 @@ class pdf_rouget extends ModelePdfExpedition
$weighttxt='';
if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
{
- $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units, "weight");
+ $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->weight_units);
}
$voltxt='';
if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
{
- $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0, "volume");
+ $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0);
}
if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
diff --git a/htdocs/core/modules/reception/doc/pdf_squille.modules.php b/htdocs/core/modules/reception/doc/pdf_squille.modules.php
index 3a8b1a78a3e..a84b86e908b 100644
--- a/htdocs/core/modules/reception/doc/pdf_squille.modules.php
+++ b/htdocs/core/modules/reception/doc/pdf_squille.modules.php
@@ -450,12 +450,12 @@ class pdf_squille extends ModelePdfReception
$weighttxt='';
if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->product->weight)
{
- $weighttxt=round($object->lines[$i]->product->weight * $object->lines[$i]->qty, 5).' '.measuring_units_string($object->lines[$i]->product->weight_units, "weight");
+ $weighttxt=round($object->lines[$i]->product->weight * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "weight", $object->lines[$i]->product->weight_units);
}
$voltxt='';
if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->product->volume)
{
- $voltxt=round($object->lines[$i]->product->volume * $object->lines[$i]->qty, 5).' '.measuring_units_string($object->lines[$i]->product->volume_units?$object->lines[$i]->product->volume_units:0, "volume");
+ $voltxt=round($object->lines[$i]->product->volume * $object->lines[$i]->qty, 5).' '.measuringUnitString(0, "volume", $object->lines[$i]->product->volume_units?$object->lines[$i]->product->volume_units:0);
}
$pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt)?'
':'').$voltxt, 0, 0, false, true, 'C');
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index d1dbb129a19..5ca83e9ebae 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1707,7 +1707,6 @@ elseif ($id || $ref)
// Print form confirm
print $formconfirm;
-
// Calculate totalWeight and totalVolume for all products
// by adding weight and volume of each product line.
$tmparray=$object->getTotalWeightVolume();
@@ -1850,16 +1849,14 @@ elseif ($id || $ref)
else
{
print $object->trueWeight;
- print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string(0, "weight", $object->weight_units):'';
+ print ($object->trueWeight && $object->weight_units!='')?' '.measuringUnitString(0, "weight", $object->weight_units):'';
}
// Calculated
if ($totalWeight > 0)
{
if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
- //print $totalWeight.' '.measuring_units_string(0, "weight");
print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
- //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
if (!empty($object->trueWeight)) print ')';
}
print '';
@@ -1867,7 +1864,7 @@ elseif ($id || $ref)
// Width
print '