From 0802df78b59cb30a2a55aec0c992c0a279b19921 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Jan 2020 17:56:02 +0100 Subject: [PATCH] Debug MRP --- htdocs/bom/bom_card.php | 20 +++++--- htdocs/core/actions_addupdatedelete.inc.php | 7 ++- htdocs/langs/en_US/mrp.lang | 1 + htdocs/langs/en_US/stocks.lang | 1 + htdocs/mrp/mo_card.php | 11 ++++- htdocs/mrp/mo_production.php | 48 +++++++------------ .../stock/class/mouvementstock.class.php | 10 ++-- 7 files changed, 55 insertions(+), 43 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index a980df3e6fc..1caa0c347b4 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -97,11 +97,13 @@ if (empty($reshook)) $backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php'; if (empty($backtopage) || ($cancel && empty($id))) { - //var_dump($backurlforlist);exit; - if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist; - else $backtopage = DOL_URL_ROOT.'/bom/bom_card.php?id='.($id > 0 ? $id : '__ID__'); + if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { + if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist; + else $backtopage = dol_buildpath('/bom/bom_card.php', 1).'?id='.($id > 0 ? $id : '__ID__'); + } } - $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record + + $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record // Actions cancel, add, update, delete or clone include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; @@ -169,7 +171,9 @@ if (empty($reshook)) } else { - unset($_POST['qty_frozen']); + unset($_POST['idprod']); + unset($_POST['qty']); + unset($_POST['qty_frozen']); unset($_POST['disable_stock_change']); } } @@ -207,7 +211,9 @@ if (empty($reshook)) } else { - unset($_POST['qty_frozen']); + unset($_POST['idprod']); + unset($_POST['qty']); + unset($_POST['qty_frozen']); unset($_POST['disable_stock_change']); } } @@ -644,7 +650,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { if ($object->status == $object::STATUS_VALIDATED && !empty($user->rights->mrp->write)) { - print ''.$langs->trans("CreateMO").''; + print ''.$langs->trans("CreateMO").''; } } diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index b30cc1a411d..59606ee65b5 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -36,7 +36,12 @@ if ($cancel) { /*var_dump($cancel); var_dump($backtopage);exit;*/ - if (!empty($backtopage)) + if (!empty($backtopageforcancel)) + { + header("Location: ".$backtopageforcancel); + exit; + } + elseif (!empty($backtopage)) { header("Location: ".$backtopage); exit; diff --git a/htdocs/langs/en_US/mrp.lang b/htdocs/langs/en_US/mrp.lang index 6bec44d66e6..faec35f6d46 100644 --- a/htdocs/langs/en_US/mrp.lang +++ b/htdocs/langs/en_US/mrp.lang @@ -54,6 +54,7 @@ ToConsume=To consume ToProduce=To produce QtyAlreadyConsumed=Qty already consumed QtyAlreadyProduced=Qty already produced +ConsumeOrProduce=Consume or Produce ConsumeAndProduceAll=Consume and Produce All Manufactured=Manufactured TheProductXIsAlreadyTheProductToProduce=The product to add is already the product to produce. diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index ecee37908ce..bcdaabb7f6e 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -143,6 +143,7 @@ InventoryCode=Movement or inventory code IsInPackage=Contained into package WarehouseAllowNegativeTransfer=Stock can be negative qtyToTranferIsNotEnough=You don't have enough stock from your source warehouse and your setup does not allow negative stocks. +qtyToTranferLotIsNotEnough=You don't have enough stock, for this lot number, from your source warehouse and your setup does not allow negative stocks (Qty for product '%s' with lot '%s' is %s in warehouse '%s'). ShowWarehouse=Show warehouse MovementCorrectStock=Stock correction for product %s MovementTransferStock=Stock transfer of product %s into another warehouse diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 68938f97a58..1993f6e46aa 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -62,6 +62,7 @@ $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); //$lineid = GETPOST('lineid', 'int'); // Initialize technical objects @@ -135,6 +136,10 @@ if (empty($reshook)) else $backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__'); } } + if ($cancel && ! empty($backtopageforcancel)) { + $backtopage = $backtopageforcancel; + } + $triggermodname = 'MRP_MO_MODIFY'; // Name of trigger action code to execute when we modify record // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen @@ -202,7 +207,8 @@ if ($action == 'create') print '
'; print ''; print ''; - print ''; + if ($backtopage) print ''; + if ($backtopageforcancel) print ''; dol_fiche_head(array(), ''); @@ -304,8 +310,9 @@ if (($id || $ref) && $action == 'edit') print ''; print ''; print ''; - print ''; print ''; + if ($backtopage) print ''; + if ($backtopageforcancel) print ''; dol_fiche_head(); diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 037fe3270b1..6a2b0e88dc4 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -157,7 +157,7 @@ if (empty($reshook)) $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_REOPEN'); } - if (in_array($action, array('confirm_consume', 'confirm_produce', 'confirm_consumeandproduceall'))) { + if (in_array($action, array('confirm_consumeorproduce', 'confirm_consumeandproduceall'))) { $stockmove = new MouvementStock($db); $labelmovement = GETPOST('inventorylabel', 'alphanohtml'); @@ -256,13 +256,13 @@ if (empty($reshook)) $error++; } } - + var_dump(GETPOST('batchtoproduce-'.$line->id.'-'.$i)); $idstockmove = 0; if (! $error && GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0) { // Record stock movement $id_product_batch = 0; $stockmove->origin = $object; - $idstockmove = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i), $qtytoprocess, 0, $labelmovement, dol_now(), '', '', GETPOST('batchtoproduce-'.$line->id.'-'.$i), $id_product_batch, $codemovement); + $idstockmove = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i), $qtytoprocess, 0, $labelmovement, '', '', GETPOST('batchtoproduce-'.$line->id.'-'.$i), dol_now(), $id_product_batch, $codemovement); if ($idstockmove < 0) { $error++; setEventMessages($stockmove->error, $stockmove->errors, 'errors'); @@ -516,7 +516,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea dol_fiche_end(); - if (! in_array($action, array('consume', 'produce', 'consumeandproduceall'))) + if (! in_array($action, array('consumeorproduce', 'consumeandproduceall'))) { print '
'; @@ -524,27 +524,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Note that $action and $object may be modified by hook $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); if (empty($reshook)) { - // Consume - + // Consume or produce if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) { if ($permissiontoproduce) { - print ''.$langs->trans('Consume').''; + print ''.$langs->trans('ConsumeOrProduce').''; } else { - print ''.$langs->trans('Consume').''; + print ''.$langs->trans('ConsumeOrProduce').''; } } elseif ($object->status == Mo::STATUS_DRAFT) { - print ''.$langs->trans('Consume').''; - } - - // Produce - if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) { - if ($permissiontoproduce) { - print ''.$langs->trans('Produce').''; - } else { - print ''.$langs->trans('Produce').''; - } - } elseif ($object->status == Mo::STATUS_DRAFT) { - print ''.$langs->trans('Produce').''; + print ''.$langs->trans('ConsumeOrProduce').''; } // ConsumeAndProduceAll @@ -571,7 +559,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'; } - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) { print ''; print ''; @@ -620,11 +608,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("Qty").''; print ''.$langs->trans("QtyAlreadyConsumed").''; print ''; - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Warehouse"); + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse"); print ''; if ($conf->productbatch->enabled) { print ''; - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Batch"); + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch"); print ''; } print ''; @@ -678,12 +666,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Show detailed of already consumed with js code to collapse //$arrayoflines = $object->fetchLinesLinked('consumed', $line->id); - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) { + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) { $i = 1; print ''; print ''.$langs->trans("ToConsume").''; $preselected = (GETPOSTISSET('qty-'.$line->id.'-'.$i) ? GETPOST('qty-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyconsumed)); - if ($action == 'produce') $preselected = 0; + if ($action == 'consumeorproduce' && ! GETPOSTISSET('qty-'.$line->id.'-'.$i)) $preselected = 0; print ''; print ''; print ''; @@ -747,11 +735,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("Qty").''; print ''.$langs->trans("QtyAlreadyProduced").''; print ''; - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Warehouse"); + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse"); print ''; if ($conf->productbatch->enabled) { print ''; - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Batch"); + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch"); print ''; } print ''; @@ -793,11 +781,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print ''; - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) { + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) { print ''; print ''.$langs->trans("ToProduce").''; $preselected = (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i) ? GETPOST('qtytoproduce-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyproduced)); - if ($action == 'consume') $preselected = 0; + if ($action == 'consumeorproduce' && ! GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) $preselected = 0; print ''; print ''; print ''; @@ -829,7 +817,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; } - if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) + if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) { print "
\n"; } diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 55e7af367b7..790db5d7c5e 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -317,14 +317,18 @@ class MouvementStock extends CommonObject { if ($batch != $batchcursor) continue; $foundforbatch=1; - if ($prodbatch->qty < abs($qty)) $qtyisnotenough=1; + if ($prodbatch->qty < abs($qty)) $qtyisnotenough = $prodbatch->qty; break; } if (! $foundforbatch || $qtyisnotenough) { $langs->load("stocks"); - $this->error = $langs->trans('qtyToTranferLotIsNotEnough').' : '.$product->ref; - $this->errors[] = $langs->trans('qtyToTranferLotIsNotEnough').' : '.$product->ref; + include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; + $tmpwarehouse = new Entrepot($this->db); + $tmpwarehouse->fetch($entrepot_id); + + $this->error = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref); + $this->errors[] = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref); $this->db->rollback(); return -8; }