FIX Stock qty hidden without permission to see stock

This commit is contained in:
Laurent Destailleur 2019-10-27 00:55:06 +02:00
parent e17cc5b2e5
commit 5cb9434bb4

View File

@ -2416,10 +2416,12 @@ class Form
// Units // Units
$outvalUnits = ''; $outvalUnits = '';
if ($conf->global->PRODUCT_USE_UNITS) { if (! empty($conf->global->PRODUCT_USE_UNITS)) {
if (!empty($objp->unit_short)) { if (!empty($objp->unit_short)) {
$outvalUnits .= ' - ' . $objp->unit_short; $outvalUnits .= ' - ' . $objp->unit_short;
} }
}
if (! empty($conf->global->PRODUCT_SHOW_DIMENSIONS_IN_COMBO)) {
if (!empty($objp->weight) && $objp->weight_units!==null) { if (!empty($objp->weight) && $objp->weight_units!==null) {
$unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs); $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs);
$outvalUnits .= ' - ' . $unitToShow; $outvalUnits .= ' - ' . $unitToShow;
@ -2436,17 +2438,17 @@ class Form
$unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs); $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs);
$outvalUnits .= ' - ' . $unitToShow; $outvalUnits .= ' - ' . $unitToShow;
} }
if ($outdurationvalue && $outdurationunit) { }
$da = array( if ($outdurationvalue && $outdurationunit) {
'h' => $langs->trans('Hour'), $da = array(
'd' => $langs->trans('Day'), 'h' => $langs->trans('Hour'),
'w' => $langs->trans('Week'), 'd' => $langs->trans('Day'),
'm' => $langs->trans('Month'), 'w' => $langs->trans('Week'),
'y' => $langs->trans('Year') 'm' => $langs->trans('Month'),
); 'y' => $langs->trans('Year')
if (isset($da[$outdurationunit])) { );
$outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : '')); if (isset($da[$outdurationunit])) {
} $outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : ''));
} }
} }
@ -2458,8 +2460,10 @@ class Form
} }
if (! empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))) if (! empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)))
{ {
if ($objp->stock > 0) $opt.= ' class="product_line_stock_ok"'; if (! empty($user->rights->stock->lire)) {
elseif ($objp->stock <= 0) $opt.= ' class="product_line_stock_too_low"'; if ($objp->stock > 0) $opt.= ' class="product_line_stock_ok"';
elseif ($objp->stock <= 0) $opt.= ' class="product_line_stock_too_low"';
}
} }
$opt.= '>'; $opt.= '>';
$opt.= $objp->ref; $opt.= $objp->ref;
@ -2602,37 +2606,39 @@ class Form
if (! empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))) if (! empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)))
{ {
$opt.= ' - '.$langs->trans("Stock").':'.$objp->stock; if (! empty($user->rights->stock->lire)) {
$opt.= ' - '.$langs->trans("Stock").':'.$objp->stock;
if ($objp->stock > 0) { if ($objp->stock > 0) {
$outval.= ' - <span class="product_line_stock_ok">'; $outval.= ' - <span class="product_line_stock_ok">';
}elseif ($objp->stock <= 0) { }elseif ($objp->stock <= 0) {
$outval.= ' - <span class="product_line_stock_too_low">'; $outval.= ' - <span class="product_line_stock_too_low">';
} }
$outval.= $langs->transnoentities("Stock").':'.$objp->stock; $outval.= $langs->transnoentities("Stock").':'.$objp->stock;
$outval.= '</span>'; $outval.= '</span>';
if (! empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) // Warning, this option may slow down combo list generation if (! empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) // Warning, this option may slow down combo list generation
{ {
$langs->load("stocks"); $langs->load("stocks");
$tmpproduct=new Product($this->db); $tmpproduct=new Product($this->db);
$tmpproduct->fetch($objp->rowid); $tmpproduct->fetch($objp->rowid);
$tmpproduct->load_virtual_stock(); $tmpproduct->load_virtual_stock();
$virtualstock = $tmpproduct->stock_theorique; $virtualstock = $tmpproduct->stock_theorique;
$opt.= ' - '.$langs->trans("VirtualStock").':'.$virtualstock; $opt.= ' - '.$langs->trans("VirtualStock").':'.$virtualstock;
$outval.=' - '.$langs->transnoentities("VirtualStock").':'; $outval.=' - '.$langs->transnoentities("VirtualStock").':';
if ($virtualstock > 0) { if ($virtualstock > 0) {
$outval.= ' - <span class="product_line_stock_ok">'; $outval.= ' - <span class="product_line_stock_ok">';
}elseif ($virtualstock <= 0) { }elseif ($virtualstock <= 0) {
$outval.= ' - <span class="product_line_stock_too_low">'; $outval.= ' - <span class="product_line_stock_too_low">';
} }
$outval.=$virtualstock; $outval.=$virtualstock;
$outval.='</span>'; $outval.='</span>';
unset($tmpproduct); unset($tmpproduct);
} }
}
} }
$opt.= "</option>\n"; $opt.= "</option>\n";