diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 6f2cbcd1955..99dd80a8b2d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3890,9 +3890,10 @@ class Form * @param string $selected Preselected Unit ID * @param string $htmlname Select name * @param int $showempty Add a nempty line + * @param string $unit_type Restrict to one given unit type * @return string HTML select */ - public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0) + public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0, $unit_type = '') { global $langs; @@ -3902,6 +3903,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) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index bc6b87a3353..d524fe22bf8 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -189,11 +189,21 @@ $coldisplay++; global->PRODUCT_USE_UNITS)) - { + 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)) { + 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 ''; - print $form->selectUnits($line->fk_unit, "units"); + print $form->selectUnits($line->fk_unit, "units", 0, $unit_type); print ''; } ?>