From b0ea276233effb689fe5fac95b612bb3c93659b5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 4 Nov 2019 14:13:36 +0100 Subject: [PATCH] Debug MO module --- htdocs/bom/bom_card.php | 18 ++-- htdocs/core/class/html.formfile.class.php | 18 ++-- .../bom/doc/doc_generic_bom_odt.modules.php | 2 +- htdocs/core/modules/bom/modules_bom.php | 2 +- htdocs/core/modules/modMrp.class.php | 2 +- .../mrp/doc/doc_generic_mo_odt.modules.php | 2 +- .../mrp/{modules_mrp.php => modules_mo.php} | 10 +- .../modulebuilder/template/myobject_card.php | 18 ++-- htdocs/mrp/mo_card.php | 91 ++++++++++++++----- 9 files changed, 107 insertions(+), 56 deletions(-) rename htdocs/core/modules/mrp/{modules_mrp.php => modules_mo.php} (93%) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 231679f7b3a..15ef270accc 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -72,14 +72,14 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu // Security check - Protection if external user //if ($user->socid > 0) access_forbidden(); //if ($user->socid > 0) $socid = $user->socid; -//$isdraft = (($object->statut == BillOfMaterials::STATUS_DRAFT) ? 1 : 0); +//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0); //$result = restrictedArea($user, 'bom', $object->id, '', '', 'fk_soc', 'rowid', $isdraft); $permissionnote=$user->rights->bom->write; // Used by the include of actions_setnotes.inc.php $permissiondellink=$user->rights->bom->write; // Used by the include of actions_dellink.inc.php $permissionedit=$user->rights->bom->write; // Used by the include of actions_lineupdown.inc.php $permissiontoadd=$user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php -$permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && $object->status == 0); +$permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); /* @@ -457,7 +457,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->bom->write) + if ($permissiontoadd) { if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; @@ -532,7 +532,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print '
'; - if (! empty($object->lines) || ($object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) + if (! empty($object->lines) && $object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline') { print ''; } @@ -555,7 +555,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - if (! empty($object->lines) || ($object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) + if (! empty($object->lines) && $object->status == $object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline') { print '
'; } @@ -565,8 +565,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } - // Buttons for actions + if ($action != 'presend' && $action != 'editline') { print '
'."\n"; $parameters=array(); @@ -584,7 +584,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Modify - if ($user->rights->bom->write) + if ($permissiontoadd) { print ''.$langs->trans("Modify").''."\n"; } @@ -619,7 +619,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Clone - if ($user->rights->bom->write) + if ($permissiontoadd) { print '' . $langs->trans("ToClone") . ''; } @@ -638,7 +638,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } */ - if ($user->rights->bom->delete) + if ($permissiontodelete) { print ''.$langs->trans('Delete').''."\n"; } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 22acff7763d..5f8a9cb51e3 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -667,21 +667,27 @@ class FormFile { $submodulepart = $modulepart; - // For normalized standard modules - $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php', 0); + // modulepart = 'nameofmodule' or 'nameofmodule:nameofsubmodule' + $tmp=explode(':', $modulepart); + if (! empty($tmp[1])) { + $modulepart=$tmp[0]; + $submodulepart=$tmp[1]; + } + + // For normalized standard modules + $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$submodulepart.'.php', 0); if (file_exists($file)) { $res=include_once $file; } - // For normalized external modules. modulepart = 'nameofmodule' or 'nameofmodule:nameofsubmodule' + // For normalized external modules. else { - $tmp=explode(':', $modulepart); - if (! empty($tmp[2])) $submodulepart=$tmp[2]; - $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$submodulepart.'.php', 0); + $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$submodulepart.'.php', 0); $res=include_once $file; } $class='ModelePDF'.ucfirst($submodulepart); + if (class_exists($class)) { $modellist=call_user_func($class.'::liste_modeles', $this->db); diff --git a/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php b/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php index 38358222282..63c4e9ea836 100644 --- a/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php +++ b/htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php @@ -38,7 +38,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php'; /** * Class to build documents using ODF templates generator */ -class doc_generic_bom_odt extends ModelePDFBoms +class doc_generic_bom_odt extends ModelePDFBom { /** * Issuer diff --git a/htdocs/core/modules/bom/modules_bom.php b/htdocs/core/modules/bom/modules_bom.php index f8f29fec2e6..45bca8a38b3 100644 --- a/htdocs/core/modules/bom/modules_bom.php +++ b/htdocs/core/modules/bom/modules_bom.php @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // requir /** * Parent class for boms models */ -abstract class ModelePDFBoms extends CommonDocGenerator +abstract class ModelePDFBom extends CommonDocGenerator { // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/core/modules/modMrp.class.php b/htdocs/core/modules/modMrp.class.php index bc85111ebd2..43908b85164 100644 --- a/htdocs/core/modules/modMrp.class.php +++ b/htdocs/core/modules/modMrp.class.php @@ -62,7 +62,7 @@ class modMrp extends DolibarrModules // Used only if file README.md and README-LL.md not found. $this->descriptionlong = "Module to Manage Manufacturing Orders (MO)"; // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' - $this->version = 'dolibarr'; + $this->version = 'experimental'; // Url to the file with your last numberversion of this module //$this->url_last_version = 'http://www.example.com/versionmodule.txt'; diff --git a/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php b/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php index 0447694465f..854c7c350b3 100644 --- a/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php +++ b/htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php @@ -38,7 +38,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php'; /** * Class to build documents using ODF templates generator */ -class doc_generic_mo_odt extends ModelePDFMos +class doc_generic_mo_odt extends ModelePDFMo { /** * Issuer diff --git a/htdocs/core/modules/mrp/modules_mrp.php b/htdocs/core/modules/mrp/modules_mo.php similarity index 93% rename from htdocs/core/modules/mrp/modules_mrp.php rename to htdocs/core/modules/mrp/modules_mo.php index bd83fab70b7..76d204a9826 100644 --- a/htdocs/core/modules/mrp/modules_mrp.php +++ b/htdocs/core/modules/mrp/modules_mo.php @@ -23,10 +23,10 @@ */ /** - * \file htdocs/core/modules/mrp/modules_mrp.php - * \ingroup bom - * \brief File that contains parent class for mos models - * and parent class for mos numbering models + * \file htdocs/core/modules/mrp/modules_mo.php + * \ingroup mrp + * \brief File that contains parent class for MOs models + * and parent class for MOs numbering models */ require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // requir /** * Parent class for mos models */ -abstract class ModelePDFMos extends CommonDocGenerator +abstract class ModelePDFMo extends CommonDocGenerator { // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 111e190bcf3..afac89985ae 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -102,14 +102,14 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu // Security check - Protection if external user //if ($user->socid > 0) access_forbidden(); //if ($user->socid > 0) $socid = $user->socid; -//$isdraft = (($object->statut == MyObject::STATUS_DRAFT) ? 1 : 0); +//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0); //$result = restrictedArea($user, 'mymodule', $object->id, '', '', 'fk_soc', 'rowid', $isdraft); $permissionnote = $user->rights->mymodule->myobject->write; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->mymodule->myobject->write; // Used by the include of actions_dellink.inc.php $permissionedit = $user->rights->mymodule->myobject->write; // Used by the include of actions_lineupdown.inc.php $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the include of actions_addupdatedelete.inc.php -$permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && $object->status == 0); +$permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); @@ -404,7 +404,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print '
'; - if (! empty($object->lines) && $object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline') + if (! empty($object->lines) && $object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline') { print ''; } @@ -457,9 +457,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Modify - if (! empty($user->rights->mymodule->myobject->write)) + if ($permissiontoadd) { - print ''.$langs->trans("Modify").''."\n"; + print ''.$langs->trans("Modify").''."\n"; } else { @@ -467,13 +467,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Clone - if (! empty($user->rights->mymodule->myobject->write)) + if ($permissiontoadd) { - print '' . $langs->trans("ToClone") . ''."\n"; + print '' . $langs->trans("ToClone") . ''."\n"; } /* - if ($user->rights->mymodule->myobject->write) + if ($permissiontoadd) { if ($object->status == 1) { @@ -487,7 +487,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea */ // Delete (need delete permission, or if draft, just need create/modify permission) - if (! empty($user->rights->mymodule->myobject->delete) || (! empty($object->fields['status']) && $object->status == $object::STATUS_DRAFT && ! empty($user->rights->mymodule->myobject->write))) + if ($permissiontodelete) { print ''.$langs->trans('Delete').''."\n"; } diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 07b6be426f3..a6742b739ac 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -90,14 +90,14 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu // Security check - Protection if external user //if ($user->socid > 0) access_forbidden(); //if ($user->socid > 0) $socid = $user->socid; -//$isdraft = (($object->statut == Mo::STATUS_DRAFT) ? 1 : 0); +//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0); //$result = restrictedArea($user, 'mrp', $object->id, '', '', 'fk_soc', 'rowid', $isdraft); $permissionnote=$user->rights->mrp->write; // Used by the include of actions_setnotes.inc.php $permissiondellink=$user->rights->mrp->write; // Used by the include of actions_dellink.inc.php $permissionedit=$user->rights->mrp->write; // Used by the include of actions_lineupdown.inc.php $permissiontoadd=$user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php -$permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && $object->status == 0); +$permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); /* @@ -132,6 +132,12 @@ if (empty($reshook)) // Actions when printing a doc from card include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; + // Actions to send emails + $trigger_name='MO_SENTBYMAIL'; + $autocopy='MAIN_MAIL_AUTOCOPY_MO_TO'; + $trackid='mo'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + // Action to move up and down lines of object //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once @@ -143,12 +149,6 @@ if (empty($reshook)) { $object->setProject(GETPOST('projectid', 'int')); } - - // Actions to send emails - $trigger_name='MO_SENTBYMAIL'; - $autocopy='MAIN_MAIL_AUTOCOPY_MO_TO'; - $trackid='mo'.$object->id; - include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; } @@ -159,6 +159,7 @@ if (empty($reshook)) */ $form=new Form($db); +$formfile=new FormFile($db); $formproject=new FormProjets($db); llxHeader('', $langs->trans('Mo'), ''); @@ -299,6 +300,46 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); } + + // 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->thirdparty); + } 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 .= '
'; + $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object); + }*/ + + $formquestion=array(); + if (! empty($conf->bom->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); + } + // Clone confirmation if ($action == 'clone') { // Create an array for form @@ -332,7 +373,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->mrp->write) + if ($permissiontoadd) { if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; @@ -366,7 +407,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'; print '
'; print '
'; - print '
'."\n"; + print '
'."\n"; // Common attributes $keyforbreak='fk_warehouse'; @@ -407,14 +448,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print '
'; - if (! empty($object->lines) && $object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline') + if (! empty($object->lines) && $object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline') { print '
'; } if (! empty($object->lines)) { - $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1); + $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/mrp/tpl'); } // Form to add new line @@ -423,14 +464,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($action != 'editline') { // Add products/services form - $object->formAddObjectLine(1, $mysoc, $soc); + $object->formAddObjectLine(1, $mysoc, $soc, '/mrp/tpl'); $parameters = array(); $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook } } - if (! empty($object->lines) && $object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline') + if (! empty($object->lines) && $object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline') { print '
'; } @@ -451,10 +492,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (empty($reshook)) { // Send - print '' . $langs->trans('SendMail') . ''."\n"; + //print '' . $langs->trans('SendMail') . ''."\n"; + + if ($user->rights->bom->write && $object->status == MO::STATUS_VALIDATED) + { + print '' . $langs->trans("SetToDraft") . ''; + } // Modify - if (! empty($user->rights->mrp->write)) + if ($permissiontoadd) { print ''.$langs->trans("Modify").''."\n"; } @@ -477,13 +523,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Clone - if (! empty($user->rights->mrp->write)) + if ($permissiontoadd) { - print ''; + print '' . $langs->trans("ToClone") . ''; } // Delete (need delete permission, or if draft, just need create/modify permission) - if (! empty($user->rights->mrp->delete) || (! empty($object->fields['status']) && $object->status == $object::STATUS_DRAFT && ! empty($user->rights->mrp->write))) + if ($permissiontodelete) { print ''.$langs->trans('Delete').''."\n"; } @@ -507,14 +553,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; // ancre // Documents - /*$objref = dol_sanitizeFileName($object->ref); - $relativepath = $comref . '/' . $comref . '.pdf'; + $objref = dol_sanitizeFileName($object->ref); + $relativepath = $objref . '/' . $objref . '.pdf'; $filedir = $conf->mrp->dir_output . '/' . $objref; $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; $genallowed = $user->rights->mrp->read; // If you can read, you can build the PDF to read content $delallowed = $user->rights->mrp->create; // If you can create/edit, you can remove a file on card - print $formfile->showdocuments('mrp', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); - */ + print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang); // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));