diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 6744af04022..66596252b77 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -421,17 +421,18 @@ class MouvementStock extends CommonObject if (isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) { $foundforbatch = 0; $qtyisnotenough = 0; + if (isset($product->stock_warehouse[$entrepot_id])) { + foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) { + if ((string) $batch != (string) $batchcursor) { // Lot '59' must be different than lot '59c' + continue; + } - foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) { - if ((string) $batch != (string) $batchcursor) { // Lot '59' must be different than lot '59c' - continue; + $foundforbatch = 1; + if ($prodbatch->qty < abs($qty)) { + $qtyisnotenough = $prodbatch->qty; + } + break; } - - $foundforbatch = 1; - if ($prodbatch->qty < abs($qty)) { - $qtyisnotenough = $prodbatch->qty; - } - break; } if (!$foundforbatch || $qtyisnotenough) { $langs->load("stocks"); @@ -445,7 +446,7 @@ class MouvementStock extends CommonObject return -8; } } else { - if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) { + if (isset($product->stock_warehouse[$entrepot_id]) && (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty))) { $langs->load("stocks"); $this->error = $langs->trans('qtyToTranferIsNotEnough').' : '.$product->ref; $this->errors[] = $langs->trans('qtyToTranferIsNotEnough').' : '.$product->ref; diff --git a/htdocs/product/stock/stocktransfer/stocktransfer_card.php b/htdocs/product/stock/stocktransfer/stocktransfer_card.php index 96b228fba9e..1d0f6dd607e 100644 --- a/htdocs/product/stock/stocktransfer/stocktransfer_card.php +++ b/htdocs/product/stock/stocktransfer/stocktransfer_card.php @@ -189,10 +189,15 @@ if (empty($reshook)) { } else { if (!empty($batch)) { $error++; - setEventMessages($langs->transnoentities('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors'); + setEventMessages($langs->transnoentities('StockTransferNoBatchForProduct', $prod->getNomUrl()), null, 'errors'); } } + if ($prod->status_batch==2 && abs($qty)>1) { + $error++; + setEventMessages($langs->transnoentities('TooManyQtyForSerialNumber', $prod->ref), null, 'errors'); + } + if (empty($error)) { $line = new StockTransferLine($db); $records = $line->fetchAll('', '', 0, 0, '(fk_stocktransfer:=:'.((int) $id).') AND (fk_product:=:'.((int) $fk_product).') AND (fk_warehouse_source:=:'.((int) $fk_warehouse_source).') AND (fk_warehouse_destination:=:'.((int) $fk_warehouse_destination).') AND ('.(empty($batch) ? "(batch:=:'') OR (batch:IS:NULL)" : "batch:=:'".$db->escape($batch)."'").')'); @@ -251,6 +256,12 @@ if (empty($reshook)) { } } + if ($prod->status_batch==2 && abs($qty)>1) { + $error++; + setEventMessages($langs->transnoentities('TooManyQtyForSerialNumber', $prod->ref), null, 'errors'); + $action = 'editline'; + } + if (empty($error)) { $line = new StockTransferLine($db); $line->fetch($lineid); @@ -446,6 +457,10 @@ if ($action == 'create') { include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; if (isModEnabled('incoterm')) { + $soc = new Societe($db); + if (!empty($object->fk_soc)) { + $soc->fetch($object->fk_soc); + } print '