From b9150c2441c2706ef2bc2cb0908f92c359d0459f Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 6 Sep 2021 11:20:36 +0200 Subject: [PATCH 1/4] add produce line if no produce objects --- htdocs/mrp/mo_production.php | 67 +++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 678865805d7..70eb96c5fe1 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -149,14 +149,19 @@ if (empty($reshook)) { $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_REOPEN'); } - if ($action == 'confirm_addconsumeline' && GETPOST('addconsumelinebutton') && $permissiontoadd) { + if (($action == 'confirm_addconsumeline' && GETPOST('addconsumelinebutton') && $permissiontoadd) + || $action == 'confirm_addproduceline' && GETPOST('addproducelinebutton') && $permissiontoadd) { $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'; + if (GETPOST('addconsumelinebutton')) { + $moline->role = 'toconsume'; + } else { + $moline->role = 'toproduce'; + } $moline->origin_type = 'free'; // free consume line $moline->position = 0; @@ -642,7 +647,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; } - if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline'))) { + if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline', 'addproduceline'))) { print '
'; print ''; print ''; @@ -962,8 +967,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'; print '
'; - print load_fiche_titre($langs->trans('Production'), '', ''); + $nblinetoproduce = 0; + foreach ($object->lines as $line) { + if ($line->role == 'toproduce') { + $nblinetoproduce++; + } + } + if (empty($nblinetoproduce)) { + if ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED && $action != 'consumeorproduce' && $action != 'consumeandproduceall') { + $newlinetext = ''.$langs->trans("AddNewProduceLines").''; + } + print load_fiche_titre($langs->trans('Production'), '', '', 0, '', '', $newlinetext); + } else { + print load_fiche_titre($langs->trans('Production'), '', '', 0); + } print '
'; print ''; @@ -993,6 +1011,34 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print ''; + if ($action == 'addproduceline') { + print ''."\n"; + print ''; + print ''; + // Qty + print ''; + // Cost price + print ''; + + // Qty already produced + print ''; + // Warehouse + print ''; + // Lot - serial + if ($conf->productbatch->enabled) { + print ''; + } + // Action + if ($permissiontodelete) { + print ''; + } + print ''; + } + if (!empty($object->lines)) { $nblinetoproduce = 0; foreach ($object->lines as $line) { @@ -1065,7 +1111,18 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; if ($conf->productbatch->enabled) { print ''; // Lot - print ''; + } + + if ($permissiontodelete && $line->origin_type == 'free') { + $href = $_SERVER["PHP_SELF"]; + $href .= '?id='.$object->id; + $href .= '&action=deleteline'; + $href .= '&lineid='.$line->id; + print ''; } print ''; From 765f0c4d1919faa8f08f47159f756a04dc75c829 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 6 Sep 2021 14:56:30 +0200 Subject: [PATCH 2/4] Close #18584 : Code enhancement of MO --- htdocs/langs/en_US/mrp.lang | 1 + htdocs/langs/fr_FR/mrp.lang | 1 + htdocs/mrp/class/mo.class.php | 6 ++++++ htdocs/mrp/mo_production.php | 13 +++++-------- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/htdocs/langs/en_US/mrp.lang b/htdocs/langs/en_US/mrp.lang index 0b779d55fbd..47d1fbe889f 100644 --- a/htdocs/langs/en_US/mrp.lang +++ b/htdocs/langs/en_US/mrp.lang @@ -74,6 +74,7 @@ NoStockChangeOnServices=No stock change on services ProductQtyToConsumeByMO=Product quantity still to consume by open MO ProductQtyToProduceByMO=Product quantity still to produce by open MO AddNewConsumeLines=Add new line to consume +AddNewProduceLines=Add new line to produce ProductsToConsume=Products to consume ProductsToProduce=Products to produce UnitCost=Unit cost diff --git a/htdocs/langs/fr_FR/mrp.lang b/htdocs/langs/fr_FR/mrp.lang index cdff650c34b..a0ab429a70c 100644 --- a/htdocs/langs/fr_FR/mrp.lang +++ b/htdocs/langs/fr_FR/mrp.lang @@ -72,6 +72,7 @@ NoStockChangeOnServices=Aucune variation de stock sur les services ProductQtyToConsumeByMO=Quantité de produit restant à consommer par OF ouvert ProductQtyToProduceByMO=Quantités restant à produire avec les OF ouverts AddNewConsumeLines=Ajouter une nouvelle ligne à consommer +AddNewProduceLines=Ajouter une nouvelle ligne à produire ProductsToConsume=Produits à consommer ProductsToProduce=Produits à produire UnitCost=Coût unitaire diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index f4069bfc518..2fc2a01a802 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -659,6 +659,12 @@ class Mo extends CommonObject $role = 'toconsume'; $moline->role = 'toproduce'; } + } else { + if ($this->mrptype == 1) { + $moline->role = 'toconsume'; + } else { + $moline->role = 'toproduce'; + } } $resultline = $moline->create($user, false); // Never use triggers here diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 70eb96c5fe1..0558e7e74a4 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -973,15 +973,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $nblinetoproduce++; } } - - if (empty($nblinetoproduce)) { - if ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED && $action != 'consumeorproduce' && $action != 'consumeandproduceall') { - $newlinetext = ''.$langs->trans("AddNewProduceLines").''; - } - print load_fiche_titre($langs->trans('Production'), '', '', 0, '', '', $newlinetext); - } else { - print load_fiche_titre($langs->trans('Production'), '', '', 0); + $newlinetext = ''; + if ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED && $action != 'consumeorproduce' && $action != 'consumeandproduceall') { + $newlinetext = ''.$langs->trans("AddNewProduceLines").''; } + print load_fiche_titre($langs->trans('Production'), '', '', 0, '', '', $newlinetext); + print '
'; print '
'; + print $form->select_produits('', 'productidtoadd', '', 0, 0, -1, 2, '', 0, array(), 0, '1', 0, 'maxwidth300'); + print ''; + print ''; + print '
'; + print ''; + print img_picto('', "delete"); + print ''; + print '
'; From 085b893074fc9b101f52231fda23b852ef7249ec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Sep 2021 14:44:52 +0200 Subject: [PATCH 3/4] Update mo_production.php --- htdocs/mrp/mo_production.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 0558e7e74a4..5d54d60c34e 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -150,7 +150,7 @@ if (empty($reshook)) { } if (($action == 'confirm_addconsumeline' && GETPOST('addconsumelinebutton') && $permissiontoadd) - || $action == 'confirm_addproduceline' && GETPOST('addproducelinebutton') && $permissiontoadd) { + || ($action == 'confirm_addproduceline' && GETPOST('addproducelinebutton') && $permissiontoadd)) { $moline = new MoLine($db); // Line to produce From dea7e83360eae558e6fe123ee675896c27ec7405 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 9 Sep 2021 15:33:06 +0200 Subject: [PATCH 4/4] update of mo_production.php --- htdocs/mrp/mo_production.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 5d54d60c34e..acdbb35dc80 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -975,7 +975,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } $newlinetext = ''; if ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED && $action != 'consumeorproduce' && $action != 'consumeandproduceall') { - $newlinetext = ''.$langs->trans("AddNewProduceLines").''; + if ($nblinetoproduce == 0 || $object->mrptype == 1) { + $newlinetext = ''.$langs->trans("AddNewProduceLines").''; + } } print load_fiche_titre($langs->trans('Production'), '', '', 0, '', '', $newlinetext);