Merge pull request #18831 from SteiniGreenwork/develop

NEW Can select existing batch numbers for a combo list (in mrp consumtion)
This commit is contained in:
Laurent Destailleur 2021-10-06 15:20:52 +02:00 committed by GitHub
commit d5d892b263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 2 deletions

View File

@ -945,7 +945,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if ($action == 'consumeorproduce' && !GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
$preselected = 0;
}
print '<td class="right"><input type="text" class="width50 right" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
$disable = '';
if (!empty($conf->global->MRP_NEVER_CONSUME_MORE_THAN_EXPECTED) && ($line->qty - $alreadyconsumed) <= 0) {
$disable = 'disabled';
}
print '<td class="right"><input type="text" class="width50 right" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'" '.$disable.' ></td>';
if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
print '<td></td>';
}
@ -967,7 +973,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>';
if ($tmpproduct->status_batch) {
$preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : '');
print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'">';
print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'" list="batch-'.$line->id.'-'.$i.'">';
print $formproduct->selectLot('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', '');
}
print '</td>';
}

View File

@ -591,6 +591,7 @@ class FormProduct
}
$out .= '<option value="'.$id.'"';
if ($selected == $id || ($selected == 'ifone' && $nboflot == 1)) {
$out .= ' selected';
}
@ -609,6 +610,66 @@ class FormProduct
return $out;
}
/**
* Return list of lot numbers (stock from product_batch) with stock location and stock qty
*
* @param string $htmlname Name of html select html
* @param int $empty 1=Can be empty, 0 if not
* @param int $fk_product show lot numbers of product with id fk_product. All from objectLines if 0.
* @param int $fk_entrepot filter lot numbers for warehouse with id fk_entrepot. All if 0.
* @param array $objectLines Only cache lot numbers for products in lines of object. If no lines only for fk_product. If no fk_product, all.
*
* @return string HTML datalist
*/
public function selectLot($htmlname = 'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array())
{
global $conf, $langs;
dol_syslog(get_class($this)."::selectLot $htmlname, $empty, $fk_product, $fk_entrepot,$objectLines", LOG_DEBUG);
$out = '';
$productIdArray = array();
if (!is_array($objectLines) || !count($objectLines)) {
if (!empty($fk_product) && $fk_product > 0) {
$productIdArray[] = (int) $fk_product;
}
} else {
foreach ($objectLines as $line) {
if ($line->fk_product) {
$productIdArray[] = $line->fk_product;
}
}
}
$nboflot = $this->loadLotStock($productIdArray);
$out .= '<datalist id="'.$htmlname.'" >';
if (!empty($fk_product) && $fk_product > 0) {
$productIdArray = array((int) $fk_product); // only show lot stock for product
} else {
foreach ($this->cache_lot as $key => $value) {
$productIdArray[] = $key;
}
}
foreach ($productIdArray as $productId) {
foreach ($this->cache_lot[$productId] as $id => $arraytypes) {
if (empty($fk_entrepot) || $fk_entrepot == $arraytypes['entrepot_id']) {
$label = $arraytypes['entrepot_label'].' - ';
$label .= $arraytypes['batch'];
$out .= '<option>'.$arraytypes['batch'].'</option>';
}
}
}
$out .= '</datalist>';
return $out;
}
/**
* Load in cache array list of lot available in stock from a given list of products
*