Debug MRP

This commit is contained in:
Laurent Destailleur 2020-01-08 17:56:02 +01:00
parent 2eb2feff04
commit 0802df78b5
7 changed files with 55 additions and 43 deletions

View File

@ -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 '<a class="butAction" href="'.DOL_URL_ROOT.'/mrp/mo_card.php?action=create&fk_bom='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.$langs->trans("CreateMO").'</a>';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/mrp/mo_card.php?action=create&fk_bom='.$object->id.'&backtopageforcancel='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.$langs->trans("CreateMO").'</a>';
}
}

View File

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

View File

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

View File

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

View File

@ -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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
dol_fiche_head(array(), '');
@ -304,8 +310,9 @@ if (($id || $ref) && $action == 'edit')
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
dol_fiche_head();

View File

@ -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 '<div class="tabsAction">';
@ -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 '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consume">'.$langs->trans('Consume').'</a>';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consumeorproduce">'.$langs->trans('ConsumeOrProduce').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('Consume').'</a>';
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ConsumeOrProduce').'</a>';
}
} elseif ($object->status == Mo::STATUS_DRAFT) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('Consume').'</a>';
}
// Produce
if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
if ($permissiontoproduce) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=produce">'.$langs->trans('Produce').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('Produce').'</a>';
}
} elseif ($object->status == Mo::STATUS_DRAFT) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('Produce').'</a>';
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('ConsumeOrProduce').'</a>';
}
// ConsumeAndProduceAll
@ -571,7 +559,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</div>';
}
if (in_array($action, array('consume', 'produce', 'consumeandproduceall')))
if (in_array($action, array('consumeorproduce', 'consumeandproduceall')))
{
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
@ -620,11 +608,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>'.$langs->trans("Qty").'</td>';
print '<td>'.$langs->trans("QtyAlreadyConsumed").'</td>';
print '<td>';
if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
print '</td>';
if ($conf->productbatch->enabled) {
print '<td>';
if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Batch");
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch");
print '</td>';
}
print '</tr>';
@ -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 '<tr>';
print '<td>'.$langs->trans("ToConsume").'</td>';
$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 '<td><input type="text" class="width50" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
print '<td></td>';
print '<td>';
@ -747,11 +735,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>'.$langs->trans("Qty").'</td>';
print '<td>'.$langs->trans("QtyAlreadyProduced").'</td>';
print '<td>';
if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
print '</td>';
if ($conf->productbatch->enabled) {
print '<td>';
if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) print $langs->trans("Batch");
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch");
print '</td>';
}
print '</tr>';
@ -793,11 +781,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
print '</tr>';
if (in_array($action, array('consume', 'produce', 'consumeandproduceall'))) {
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
print '<tr>';
print '<td>'.$langs->trans("ToProduce").'</td>';
$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 '<td><input type="text" class="width50" name="qtytoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
print '<td></td>';
print '<td>';
@ -829,7 +817,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</div>';
}
if (in_array($action, array('consume', 'produce', 'consumeandproduceall')))
if (in_array($action, array('consumeorproduce', 'consumeandproduceall')))
{
print "</form>\n";
}

View File

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