Fix unit selection on object edit line

This commit is contained in:
ATM john 2021-01-06 15:15:51 +01:00
parent 007ae59788
commit ae7b8e7f5e
2 changed files with 16 additions and 2 deletions

View File

@ -3892,7 +3892,7 @@ class Form
* @param int $showempty Add a nempty line
* @return string HTML select
*/
public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0)
public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0, $unit_type = false)
{
global $langs;
@ -3902,6 +3902,9 @@ class Form
$sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units';
$sql .= ' WHERE active > 0';
if(!empty($unit_type)){
$sql .= ' AND unit_type = "'.$this->db->escape($unit_type).'" ';
}
$resql = $this->db->query($sql);
if ($resql && $this->db->num_rows($resql) > 0)

View File

@ -191,9 +191,20 @@ $coldisplay++;
<?php
if (!empty($conf->global->PRODUCT_USE_UNITS))
{
$unit_type = false;
// limit unit select to unit type
if(!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)){
if(!class_exists('CUnits')) include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php';
$cUnit = new CUnits($line->db);
if($cUnit->fetch($line->fk_unit) > 0){
if(!empty($cUnit->unit_type)){
$unit_type = $cUnit->unit_type;
}
}
}
$coldisplay++;
print '<td class="left">';
print $form->selectUnits($line->fk_unit, "units");
print $form->selectUnits($line->fk_unit, "units", 0, $unit_type);
print '</td>';
}
?>