Debug MRP module
This commit is contained in:
parent
6be746e219
commit
139dfc3022
@ -66,3 +66,6 @@ AutoCloseMO=Close automatically the Manufacturing Order if quantities to consume
|
||||
NoStockChangeOnServices=No stock change on services
|
||||
ProductQtyToConsumeByMO=Product quantity still to consume by open MO
|
||||
ProductQtyToProduceByMO=Product quentity still to produce by open MO
|
||||
AddNewConsumeLines=Add new line to consume
|
||||
ProductsToConsume=Products to consume
|
||||
ProductsToProduce=Products to produce
|
||||
@ -573,66 +573,69 @@ class Mo extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
// Insert lines in mrp_production table from BOM data
|
||||
if (!$error && $this->fk_bom > 0)
|
||||
if (!$error)
|
||||
{
|
||||
// TODO Check that production has not started. If yes, we stop here.
|
||||
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'mrp_production WHERE fk_mo = '.$this->id;
|
||||
$this->db->query($sql);
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
|
||||
$bom = new Bom($this->db);
|
||||
$bom->fetch($this->fk_bom);
|
||||
if ($bom->id > 0)
|
||||
{
|
||||
$moline = new MoLine($this->db);
|
||||
$moline = new MoLine($this->db);
|
||||
|
||||
// Line to produce
|
||||
$moline->fk_mo = $this->id;
|
||||
$moline->qty = $this->qty;
|
||||
$moline->fk_product = $this->fk_product;
|
||||
$moline->role = 'toproduce';
|
||||
$moline->position = 1;
|
||||
// Line to produce
|
||||
$moline->fk_mo = $this->id;
|
||||
$moline->qty = $this->qty;
|
||||
$moline->fk_product = $this->fk_product;
|
||||
$moline->role = 'toproduce';
|
||||
$moline->position = 1;
|
||||
|
||||
$resultline = $moline->create($user, false); // Never use triggers here
|
||||
if ($resultline <= 0) {
|
||||
$error++;
|
||||
$this->error = $moline->error;
|
||||
$this->errors = $moline->errors;
|
||||
dol_print_error($this->db, $moline->error, $moline->errors);
|
||||
}
|
||||
$resultline = $moline->create($user, false); // Never use triggers here
|
||||
if ($resultline <= 0) {
|
||||
$error++;
|
||||
$this->error = $moline->error;
|
||||
$this->errors = $moline->errors;
|
||||
dol_print_error($this->db, $moline->error, $moline->errors);
|
||||
}
|
||||
|
||||
// Lines to consume
|
||||
if (! $error) {
|
||||
foreach ($bom->lines as $line)
|
||||
{
|
||||
$moline = new MoLine($this->db);
|
||||
if ($this->fk_bom > 0) { // If a BOM is defined, we know what to consume.
|
||||
include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
|
||||
$bom = new Bom($this->db);
|
||||
$bom->fetch($this->fk_bom);
|
||||
if ($bom->id > 0)
|
||||
{
|
||||
// Lines to consume
|
||||
if (! $error) {
|
||||
foreach ($bom->lines as $line)
|
||||
{
|
||||
$moline = new MoLine($this->db);
|
||||
|
||||
$moline->fk_mo = $this->id;
|
||||
if ($line->qty_frozen) {
|
||||
$moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce
|
||||
} else {
|
||||
$moline->qty = round($line->qty * $this->qty / $bom->efficiency, 2);
|
||||
}
|
||||
if ($moline->qty <= 0) {
|
||||
$error++;
|
||||
$this->error = "BadValueForquantityToConsume";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
$moline->fk_product = $line->fk_product;
|
||||
$moline->role = 'toconsume';
|
||||
$moline->position = $line->position;
|
||||
$moline->qty_frozen = $line->qty_frozen;
|
||||
$moline->disable_stock_change = $line->disable_stock_change;
|
||||
|
||||
$resultline = $moline->create($user, false); // Never use triggers here
|
||||
if ($resultline <= 0) {
|
||||
$moline->fk_mo = $this->id;
|
||||
if ($line->qty_frozen) {
|
||||
$moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce
|
||||
} else {
|
||||
$moline->qty = round($line->qty * $this->qty / $bom->efficiency, 2);
|
||||
}
|
||||
if ($moline->qty <= 0) {
|
||||
$error++;
|
||||
$this->error = $moline->error;
|
||||
$this->errors = $moline->errors;
|
||||
dol_print_error($this->db, $moline->error, $moline->errors);
|
||||
$this->error = "BadValueForquantityToConsume";
|
||||
break;
|
||||
}
|
||||
else {
|
||||
$moline->fk_product = $line->fk_product;
|
||||
$moline->role = 'toconsume';
|
||||
$moline->position = $line->position;
|
||||
$moline->qty_frozen = $line->qty_frozen;
|
||||
$moline->disable_stock_change = $line->disable_stock_change;
|
||||
|
||||
$resultline = $moline->create($user, false); // Never use triggers here
|
||||
if ($resultline <= 0) {
|
||||
$error++;
|
||||
$this->error = $moline->error;
|
||||
$this->errors = $moline->errors;
|
||||
dol_print_error($this->db, $moline->error, $moline->errors);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1416,6 +1419,11 @@ class MoLine extends CommonObjectLine
|
||||
*/
|
||||
public function create(User $user, $notrigger = false)
|
||||
{
|
||||
if (empty($this->qty)) {
|
||||
$this->error = 'BadValueForQty';
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $this->createCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
|
||||
@ -518,7 +518,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '</tr>';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("ToConsume").'</td>';
|
||||
print '<td>'.$langs->trans("ProductsToConsume").'</td>';
|
||||
print '<td>';
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
@ -537,7 +537,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '</tr>';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("ToProduce").'</td>';
|
||||
print '<td>'.$langs->trans("ProductsToProduce").'</td>';
|
||||
print '<td>';
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
|
||||
@ -162,6 +162,25 @@ if (empty($reshook))
|
||||
$result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_REOPEN');
|
||||
}
|
||||
|
||||
if ($action == 'confirm_addconsumeline' && GETPOST('addconsumelinebutton')) {
|
||||
$moline = new MoLine($db);
|
||||
|
||||
// Line to produce
|
||||
$moline->fk_mo = $object->id;
|
||||
$moline->qty = GETPOST('qtytoadd', 'int');;
|
||||
$moline->fk_product = GETPOST('productidtoadd', 'int');
|
||||
$moline->role = 'toconsume';
|
||||
$moline->position = 0;
|
||||
|
||||
$resultline = $moline->create($user, false); // Never use triggers here
|
||||
if ($resultline <= 0) {
|
||||
$error++;
|
||||
setEventMessages($moline->error, $molines->errors, 'errors');
|
||||
}
|
||||
|
||||
$action = '';
|
||||
}
|
||||
|
||||
if (in_array($action, array('confirm_consumeorproduce', 'confirm_consumeandproduceall'))) {
|
||||
$stockmove = new MouvementStock($db);
|
||||
|
||||
@ -425,21 +444,43 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
|
||||
}
|
||||
|
||||
// Confirmation of action xxxx
|
||||
if ($action == 'xxx')
|
||||
// Confirmation of validation
|
||||
if ($action == 'validate')
|
||||
{
|
||||
// We check that object has a temporary ref
|
||||
$ref = substr($object->ref, 1, 4);
|
||||
if ($ref == 'PROV') {
|
||||
$object->fetch_product();
|
||||
$numref = $object->getNextNumRef($object->fk_product);
|
||||
} else {
|
||||
$numref = $object->ref;
|
||||
}
|
||||
|
||||
$text = $langs->trans('ConfirmValidateMo', $numref);
|
||||
/*if (! empty($conf->notification->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
|
||||
$notify = new Notify($db);
|
||||
$text .= '<br>';
|
||||
$text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
|
||||
}*/
|
||||
|
||||
$formquestion = array();
|
||||
/*
|
||||
$forcecombo=0;
|
||||
if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
|
||||
$formquestion = array(
|
||||
// 'text' => $langs->trans("ConfirmClone"),
|
||||
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
|
||||
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
|
||||
// array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
|
||||
);
|
||||
*/
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
|
||||
if (!empty($conf->mrp->enabled))
|
||||
{
|
||||
$langs->load("mrp");
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
|
||||
$formproduct = new FormProduct($db);
|
||||
$forcecombo = 0;
|
||||
if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
|
||||
$formquestion = array(
|
||||
// 'text' => $langs->trans("ConfirmClone"),
|
||||
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
|
||||
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
|
||||
);
|
||||
}
|
||||
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
|
||||
}
|
||||
|
||||
// Call Hook formConfirm
|
||||
@ -530,6 +571,23 @@ 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)) {
|
||||
// Validate
|
||||
if ($object->status == $object::STATUS_DRAFT)
|
||||
{
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0))
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Consume or produce
|
||||
if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
|
||||
if ($permissiontoproduce) {
|
||||
@ -578,7 +636,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
if (in_array($action, array('consumeorproduce', 'consumeandproduceall')))
|
||||
if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline')))
|
||||
{
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
@ -586,20 +644,22 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
||||
print '<input type="hidden" name="id" value="'.$id.'">';
|
||||
|
||||
$defaultstockmovementlabel = GETPOST('inventorylabel', 'alphanohtml') ? GETPOST('inventorylabel', 'alphanohtml') : $langs->trans("ProductionForRef", $object->ref);
|
||||
//$defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : $object->ref.'_'.dol_print_date(dol_now(), 'dayhourlog');
|
||||
$defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : $langs->trans("ProductionForRef", $object->ref);
|
||||
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
|
||||
$defaultstockmovementlabel = GETPOST('inventorylabel', 'alphanohtml') ? GETPOST('inventorylabel', 'alphanohtml') : $langs->trans("ProductionForRef", $object->ref);
|
||||
//$defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : $object->ref.'_'.dol_print_date(dol_now(), 'dayhourlog');
|
||||
$defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : $langs->trans("ProductionForRef", $object->ref);
|
||||
|
||||
print '<div class="center">';
|
||||
print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ConfirmProductionDesc", $langs->transnoentitiesnoconv("Confirm")).'<br></span>';
|
||||
print $langs->trans("MovementLabel").': <input type="text" class="minwidth300" name="inventorylabel" value="'.$defaultstockmovementlabel.'"> ';
|
||||
print $langs->trans("InventoryCode").': <input type="text" class="maxwidth200" name="inventorycode" value="'.$defaultstockmovementcode.'"><br><br>';
|
||||
print '<input type="checkbox" id="autoclose" name="autoclose" value="1"'.(GETPOSTISSET('inventorylabel') ? (GETPOST('autoclose') ? ' checked="checked"' : '') : ' checked="checked"').'> <label for="autoclose">'.$langs->trans("AutoCloseMO").'</label><br>';
|
||||
print '<input class="button" type="submit" value="'.$langs->trans("Confirm").'" name="confirm">';
|
||||
print ' ';
|
||||
print '<input class="button" type="submit" value="'.$langs->trans("Cancel").'" name="cancel">';
|
||||
print '</div>';
|
||||
print '<br>';
|
||||
print '<div class="center">';
|
||||
print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ConfirmProductionDesc", $langs->transnoentitiesnoconv("Confirm")).'<br></span>';
|
||||
print $langs->trans("MovementLabel").': <input type="text" class="minwidth300" name="inventorylabel" value="'.$defaultstockmovementlabel.'"> ';
|
||||
print $langs->trans("InventoryCode").': <input type="text" class="maxwidth200" name="inventorycode" value="'.$defaultstockmovementcode.'"><br><br>';
|
||||
print '<input type="checkbox" id="autoclose" name="autoclose" value="1"'.(GETPOSTISSET('inventorylabel') ? (GETPOST('autoclose') ? ' checked="checked"' : '') : ' checked="checked"').'> <label for="autoclose">'.$langs->trans("AutoCloseMO").'</label><br>';
|
||||
print '<input class="button" type="submit" value="'.$langs->trans("Confirm").'" name="confirm">';
|
||||
print ' ';
|
||||
print '<input class="button" type="submit" value="'.$langs->trans("Cancel").'" name="cancel">';
|
||||
print '</div>';
|
||||
print '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -618,7 +678,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '<div class="fichehalfleft">';
|
||||
print '<div class="clearboth"></div>';
|
||||
|
||||
print load_fiche_titre($langs->trans('Consumption'), '', '');
|
||||
$newlinetext = '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addconsumeline">'.$langs->trans("AddNewConsumeLines").'</a>';
|
||||
print load_fiche_titre($langs->trans('Consumption'), '', '', 0, '', '', $newlinetext);
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder noshadow centpercent'.' nobottom'.'">';
|
||||
@ -637,6 +698,22 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
if ($action == 'addconsumeline') {
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>';
|
||||
print $form->select_produits('', 'productidtoadd', '', 0, 0, -1, 2);
|
||||
print '</td>';
|
||||
print '<td class="right"><input type="text" name="qtytoadd" value="1"></td>';
|
||||
print '<td class="right"></td>';
|
||||
print '<td>';
|
||||
print '<input type="submit" class="button" name="addconsumelinebutton" value="'.$langs->trans("Add").'">';
|
||||
print '</td>';
|
||||
if ($conf->productbatch->enabled) {
|
||||
print '<td></td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
$nblinetoconsume = 0;
|
||||
@ -900,7 +977,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
if (in_array($action, array('consumeorproduce', 'consumeandproduceall')))
|
||||
if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline')))
|
||||
{
|
||||
print "</form>\n";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user