Merge pull request #15910 from atm-john/new/unit_type_selection_limit

NEW unit selection on object edit line
This commit is contained in:
Laurent Destailleur 2021-01-07 10:33:07 +01:00 committed by GitHub
commit a1d20ed9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -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)

View File

@ -189,11 +189,21 @@ $coldisplay++;
</td>
<?php
if (!empty($conf->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 '<td class="left">';
print $form->selectUnits($line->fk_unit, "units");
print $form->selectUnits($line->fk_unit, "units", 0, $unit_type);
print '</td>';
}
?>