From 64d29709d5785edf014ae3e5aeb65196940f7796 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Dec 2017 18:12:29 +0100 Subject: [PATCH] FIX #7881 error not reported/blocking when subprodut need lot --- htdocs/expedition/class/expedition.class.php | 1 - htdocs/langs/en_US/errors.lang | 3 ++- .../stock/class/mouvementstock.class.php | 23 +++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 342b7a3aa1f..c0cd5896e2d 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -644,7 +644,6 @@ class Expedition extends CommonObject $langs->load("agenda"); // Loop on each product line to add a stock movement - // TODO in future, shipment lines may not be linked to order line $sql = "SELECT cd.fk_product, cd.subprice,"; $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,"; $sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock"; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 36e80586d2a..64dcd06cb65 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -205,7 +205,8 @@ ErrorChooseBetweenFreeEntryOrPredefinedProduct=You must choose if article is a p ErrorDiscountLargerThanRemainToPaySplitItBefore=The discount you try to apply is larger than remain to pay. Split the discount in 2 smaller discounts before. ErrorFileNotFoundWithSharedLink=File was not found. May be the share key was modified or file was removed recently. ErrorProductBarCodeAlreadyExists=The product barcode %s already exists on another product reference. - +ErrorNoteAlsoThatSubProductCantBeFollowedByLot=Note also that using virtual product to have auto increase/decrease of subproducts is not possible when at least one subproduct (or subproduct of subproducts) needs a serial/lot number. + # Warnings WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 2c889d589df..69be51f11e8 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -618,6 +618,8 @@ class MouvementStock extends CommonObject */ function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='') { + global $langs; + $error = 0; $pids = array(); $pqtys = array(); @@ -627,7 +629,7 @@ class MouvementStock extends CommonObject $sql.= " WHERE fk_product_pere = ".$idProduct; $sql.= " AND incdec = 1"; - dol_syslog(get_class($this)."::_createSubProduct", LOG_DEBUG); + dol_syslog(get_class($this)."::_createSubProduct for parent product ".$idProduct, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -648,9 +650,22 @@ class MouvementStock extends CommonObject // Create movement for each subproduct foreach($pids as $key => $value) { - $tmpmove = clone $this; - $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode); // This will also call _createSubProduct making this recursive - unset($tmpmove); + if (! $error) + { + $tmpmove = clone $this; + $result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode); // This will also call _createSubProduct making this recursive + if ($result < 0) + { + $this->error = $tmpmove->error; + $this->errors = array_merge($this->errors, $tmpmove->errors); + if ($result == -2) + { + $this->errors[] = $langs->trans("ErrorNoteAlsoThatSubProductCantBeFollowedByLot"); + } + $error = $result; + } + unset($tmpmove); + } } return $error;