From acea36acf2900eda0f87ea1c287916d960fd0093 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Fri, 5 Mar 2021 08:39:30 +0100 Subject: [PATCH] better check for unicity --- htdocs/langs/en_US/productbatch.lang | 2 +- htdocs/langs/fr_FR/productbatch.lang | 2 +- .../product/stock/class/mouvementstock.class.php | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index 37c34b9caed..36adfd571fb 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -25,4 +25,4 @@ ShowCurrentStockOfLot=Show current stock for couple product/lot ShowLogOfMovementIfLot=Show log of movements for couple product/lot StockDetailPerBatch=Stock detail per lot SerialNumberAlreadyInUse=Serial number %s is already used for product %s - +TooManyQtyForSerialNumber=You can only have one product %s for serial number %S diff --git a/htdocs/langs/fr_FR/productbatch.lang b/htdocs/langs/fr_FR/productbatch.lang index edfd928453c..94ceb434bfd 100644 --- a/htdocs/langs/fr_FR/productbatch.lang +++ b/htdocs/langs/fr_FR/productbatch.lang @@ -25,4 +25,4 @@ ShowCurrentStockOfLot=Afficher le stock actuel pour le couple produit / lot ShowLogOfMovementIfLot=Afficher l'historique des mouvements de couple produit / lot StockDetailPerBatch=Stock détaillé par lot SerialNumberAlreadyInUse=Le numéro de série %s est déjà utilisé pour le produit %s - +TooManyQtyForSerialNumber=Vous ne pouvez avoir qu'un produit %s avec le numéro de série %s diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 29eb5a1269f..b7000ebb557 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -569,10 +569,18 @@ class MouvementStock extends CommonObject if (!$error && !empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch) { // check unicity for serial numbered equipments ( different for lots managed products) - if ( $product->status_batch == 2 && $qty > 0 && $this->getBatchCount($fk_product, $batch) > 0 ) + if ( $product->status_batch == 2 && $qty > 0 ) { - $error++; - $this->errors[] = $langs->trans("SerialNumberAlreadyInUse", $batch, $product->ref); + if ( $this->getBatchCount($fk_product, $batch) > 0 ) + { + $error++; + $this->errors[] = $langs->trans("SerialNumberAlreadyInUse", $batch, $product->ref); + } + elseif { $qty > 1 } + { + $error++; + $this->errors[] = $langs->trans("TooManyQtyForSerialNumber", $product->ref, $batch); + } } if ( ! $error )