FIX #7881 error not reported/blocking when subprodut need lot

This commit is contained in:
Laurent Destailleur 2017-12-01 18:12:29 +01:00
parent 4969ae2abb
commit 64d29709d5
3 changed files with 21 additions and 6 deletions

View File

@ -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";

View File

@ -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

View File

@ -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;