Fix replenishment must exclude parent of variants.

This commit is contained in:
Laurent Destailleur 2020-11-13 11:28:02 +01:00
parent a98d025f5a
commit 8aaee7fa5e
2 changed files with 62 additions and 63 deletions

View File

@ -34,7 +34,7 @@ StockMovementForId=Movement ID %d
ListMouvementStockProject=List of stock movements associated to project
StocksArea=Warehouses area
AllWarehouses=All warehouses
IncludeEmptyDesiredStock=Include also undefined desired stock
IncludeEmptyDesiredStock=Include also negative stock with undefined desired stock
IncludeAlsoDraftOrders=Include also draft orders
Location=Location
LocationSummary=Short name location

View File

@ -352,7 +352,9 @@ if (dol_strlen($type)) {
if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
if ($search_label) $sql .= natural_search('p.label', $search_label);
$sql .= ' AND p.tobuy = 1';
if (!empty($canvas)) $sql .= ' AND p.canvas = "'.$db->escape($canvas).'"';
if (empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { // Add test to exclude products that has variants
$sql .= ' AND p.rowid NOT IN (SELECT pac.fk_product_parent FROM '.MAIN_DB_PREFIX.'product_attribute_combination as pac WHERE pac.entity IN ('.getEntity('product').'))';
}
$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$sql .= ', p.duration, p.tobuy';
@ -538,13 +540,13 @@ if ($usevirtualstock == 1)
{
print $langs->trans("CurentSelectionMode").': ';
print '<span class="a-mesure">'.$langs->trans("UseVirtualStock").'</span>';
print ' <a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?mode=physical&fk_supplier='.$fk_supplier.'&fk_entrepot='.$fk_entrepot.'">'.$langs->trans("UsePhysicalStock").'</a>';
print ' <a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?mode=physical'.($fk_supplier > 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UsePhysicalStock").'</a>';
print '<br>';
}
if ($usevirtualstock == 0)
{
print $langs->trans("CurentSelectionMode").': ';
print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?mode=virtual&fk_supplier='.$fk_supplier.'&fk_entrepot='.$fk_entrepot.'">'.$langs->trans("UseVirtualStock").'</a>';
print '<a class="a-mesure-disabled" href="'.$_SERVER["PHP_SELF"].'?mode=virtual'.($fk_supplier > 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UseVirtualStock").'</a>';
print ' <span class="a-mesure">'.$langs->trans("UsePhysicalStock").'</span>';
print '<br>';
}
@ -600,8 +602,8 @@ if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST('
$filters .= '&salert='.urlencode($salert);
$filters .= '&draftorder='.urlencode($draftorder);
$filters .= '&mode='.urlencode($mode);
$filters .= '&fk_supplier='.urlencode($fk_supplier);
$filters .= '&fk_entrepot='.urlencode($fk_entrepot);
if ($fk_supplier > 0) $filters .= '&fk_supplier='.urlencode($fk_supplier);
if ($fk_entrepot > 0) $filters .= '&fk_entrepot='.urlencode($fk_entrepot);
} else {
$filters = '&search_ref='.urlencode($search_ref).'&search_label='.urlencode($search_label);
$filters .= '&fourn_id='.urlencode($fourn_id);
@ -609,8 +611,8 @@ if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST('
$filters .= '&='.urlencode($salert);
$filters .= '&draftorder='.urlencode($draftorder);
$filters .= '&mode='.urlencode($mode);
$filters .= '&fk_supplier='.urlencode($fk_supplier);
$filters .= '&fk_entrepot='.urlencode($fk_entrepot);
if ($fk_supplier > 0) $filters .= '&fk_supplier='.urlencode($fk_supplier);
if ($fk_entrepot > 0) $filters .= '&fk_entrepot='.urlencode($fk_entrepot);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$filters .= '&limit='.urlencode($limit);
@ -815,67 +817,64 @@ while ($i < ($limit ? min($num, $limit) : $num))
$picto = img_picto($langs->trans("NoPendingReceptionOnSupplierOrder"), 'help');
}
$variants = $prod->hasVariants();
if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) {
print '<tr class="oddeven">';
print '<tr class="oddeven">';
// Select field
print '<td><input type="checkbox" class="check" name="choose'.$i.'"></td>';
// Select field
print '<td><input type="checkbox" class="check" name="choose'.$i.'"></td>';
print '<td class="nowrap">'.$prod->getNomUrl(1, 'stock').'</td>';
print '<td class="nowrap">'.$prod->getNomUrl(1, 'stock').'</td>';
print '<td>'.$objp->label;
print '<input type="hidden" name="desc'.$i.'" value="'.dol_escape_htmltag($objp->description).'">'; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST
print '</td>';
print '<td>'.$objp->label;
print '<input type="hidden" name="desc'.$i.'" value="'.dol_escape_htmltag($objp->description).'">'; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST
print '</td>';
if (!empty($conf->service->enabled) && $type == 1)
{
$regs = array();
if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
$duration = $regs[1].' '.$langs->trans('DurationYear');
} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
$duration = $regs[1].' '.$langs->trans('DurationMonth');
} elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
$duration = $regs[1].' '.$langs->trans('DurationDay');
} else {
$duration = $objp->duration;
}
print '<td class="center">'.$duration.'</td>';
if (!empty($conf->service->enabled) && $type == 1)
{
$regs = array();
if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
$duration = $regs[1].' '.$langs->trans('DurationYear');
} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
$duration = $regs[1].' '.$langs->trans('DurationMonth');
} elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
$duration = $regs[1].' '.$langs->trans('DurationDay');
} else {
$duration = $objp->duration;
}
// Desired stock
print '<td class="right">'.($fk_entrepot > 0 ? $desiredstockwarehouse : $desiredstock).'</td>';
// Limit stock for alert
print '<td class="right">'.($fk_entrepot > 0 ? $alertstockwarehouse : $alertstock).'</td>';
// Current stock (all warehouses)
print '<td class="right">'.$warning.$stock.'</td>';
// Current stock (warehouse selected only)
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
{
print '<td class="right">'.$warningwarehouse.$stockwarehouse.'</td>';
}
// Already ordered
print '<td class="right"><a href="replenishorders.php?search_product='.$prod->id.'">'.$ordered.'</a> '.$picto.'</td>';
// To order
print '<td class="right"><input type="text" size="4" name="tobuy'.$i.'" value="'.($fk_entrepot > 0 ? $stocktobuywarehouse : $stocktobuy).'"></td>';
// Supplier
print '<td class="right">';
print $form->select_product_fourn_price($prod->id, 'fourn'.$i, $fk_supplier);
print '</td>';
// Fields from hook
$parameters = array('objp'=>$objp);
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print '</tr>';
print '<td class="center">'.$duration.'</td>';
}
// Desired stock
print '<td class="right">'.($fk_entrepot > 0 ? $desiredstockwarehouse : $desiredstock).'</td>';
// Limit stock for alert
print '<td class="right">'.($fk_entrepot > 0 ? $alertstockwarehouse : $alertstock).'</td>';
// Current stock (all warehouses)
print '<td class="right">'.$warning.$stock.'</td>';
// Current stock (warehouse selected only)
if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0)
{
print '<td class="right">'.$warningwarehouse.$stockwarehouse.'</td>';
}
// Already ordered
print '<td class="right"><a href="replenishorders.php?search_product='.$prod->id.'">'.$ordered.'</a> '.$picto.'</td>';
// To order
print '<td class="right"><input type="text" size="4" name="tobuy'.$i.'" value="'.($fk_entrepot > 0 ? $stocktobuywarehouse : $stocktobuy).'"></td>';
// Supplier
print '<td class="right">';
print $form->select_product_fourn_price($prod->id, 'fourn'.$i, $fk_supplier);
print '</td>';
// Fields from hook
$parameters = array('objp'=>$objp);
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print '</tr>';
}
$i++;
}