From 5b6ace387e155d7230ba8a6086bb429cab3b3608 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 9 Nov 2019 19:47:49 +0100 Subject: [PATCH] Debug BOM and MO module --- htdocs/bom/bom_card.php | 1 + htdocs/bom/class/bom.class.php | 3 +- htdocs/core/actions_builddoc.inc.php | 43 +++++++++++-------- .../bom/doc/doc_generic_bom_odt.modules.php | 2 +- .../mrp/doc/doc_generic_mo_odt.modules.php | 4 +- htdocs/core/modules/mrp/mod_mo_advanced.php | 2 +- htdocs/core/modules/mrp/mod_mo_standard.php | 2 +- .../doc/doc_generic_myobject_odt.modules.php | 2 +- .../modulebuilder/template/myobject_card.php | 2 +- htdocs/mrp/class/mo.class.php | 2 +- htdocs/mrp/mo_card.php | 1 + 11 files changed, 36 insertions(+), 28 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 2e44074106b..ea3aba8b7e7 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -79,6 +79,7 @@ $permissionnote=$user->rights->bom->write; // Used by the include of actions_set $permissiondellink=$user->rights->bom->write; // Used by the include of actions_dellink.inc.php $permissiontoadd=$user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$upload_dir = $conf->bom->multidir_output[isset($object->entity)?$object->entity:1]; /* diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index a95b6612d99..399da6e1d2c 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -88,7 +88,8 @@ class BOM extends CommonObject */ public $fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",), - 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'noteditable'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of BOM", 'showoncombobox'=>'1',), + 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5), + 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'noteditable'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of BOM", 'showoncombobox'=>'1',), 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'notnull'=>1, 'searchall'=>1, 'showoncombobox'=>'1',), 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'notnull'=>-1,), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:1:(finished IS NULL or finished <> 0)', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'), diff --git a/htdocs/core/actions_builddoc.inc.php b/htdocs/core/actions_builddoc.inc.php index 9b3b24eb41f..391d4df5cb5 100644 --- a/htdocs/core/actions_builddoc.inc.php +++ b/htdocs/core/actions_builddoc.inc.php @@ -110,27 +110,32 @@ if ($action == 'builddoc' && $permissiontoadd) // Delete file in doc form if ($action == 'remove_file' && $permissiontoadd) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + if (! empty($upload_dir)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if (empty($object->id) || ! $object->id > 0) - { - // Reload to get all modified line records and be ready for hooks - $ret = $object->fetch($id); - $ret = $object->fetch_thirdparty(); - } + if (empty($object->id) || ! $object->id > 0) + { + // Reload to get all modified line records and be ready for hooks + $ret = $object->fetch($id); + $ret = $object->fetch_thirdparty(); + } - $langs->load("other"); - $filetodelete=GETPOST('file', 'alpha'); - $file = $upload_dir . '/' . $filetodelete; - $ret=dol_delete_file($file, 0, 0, 0, $object); - if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); - else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); + $langs->load("other"); + $filetodelete=GETPOST('file', 'alpha'); + $file = $upload_dir . '/' . $filetodelete; + $ret=dol_delete_file($file, 0, 0, 0, $object); + if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); + else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); - // Make a redirect to avoid to keep the remove_file into the url that create side effects - $urltoredirect = $_SERVER['REQUEST_URI']; - $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); - $urltoredirect = preg_replace('/action=remove_file&?/', '', $urltoredirect); + // Make a redirect to avoid to keep the remove_file into the url that create side effects + $urltoredirect = $_SERVER['REQUEST_URI']; + $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); + $urltoredirect = preg_replace('/action=remove_file&?/', '', $urltoredirect); - header('Location: '.$urltoredirect); - exit; + header('Location: '.$urltoredirect); + exit; + } + else { + setEventMessages('BugFoundVarUploaddirnotDefined', null, 'errors'); + } } 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 0622f5edd13..a4ffdbf5c95 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 @@ -237,7 +237,7 @@ class doc_generic_bom_odt extends ModelePDFBom } } - $dir = $conf->bom->multidir_output[$object->entity]; + $dir = $conf->bom->multidir_output[isset($object->entity)?$object->entity:1]; $objectref = dol_sanitizeFileName($object->ref); if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref; $file = $dir . "/" . $objectref . ".odt"; 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 84602928cd9..07a1d542644 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 @@ -27,7 +27,7 @@ * \brief File of class to build ODT documents for MOs */ -require_once DOL_DOCUMENT_ROOT.'/core/modules/mrp/modules_mrp.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/mrp/modules_mo.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -244,7 +244,7 @@ class doc_generic_mo_odt extends ModelePDFMo } } - $dir = $conf->mrp->multidir_output[$object->entity]; + $dir = $conf->mrp->multidir_output[isset($object->entity)?$object->entity:1]; $objectref = dol_sanitizeFileName($object->ref); if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref; $file = $dir . "/" . $objectref . ".odt"; diff --git a/htdocs/core/modules/mrp/mod_mo_advanced.php b/htdocs/core/modules/mrp/mod_mo_advanced.php index 42c506194f3..1059ec4a9c5 100644 --- a/htdocs/core/modules/mrp/mod_mo_advanced.php +++ b/htdocs/core/modules/mrp/mod_mo_advanced.php @@ -26,7 +26,7 @@ * \brief File containing class for numbering model of MOs advanced */ -require_once DOL_DOCUMENT_ROOT .'/core/modules/mrp/modules_mrp.php'; +require_once DOL_DOCUMENT_ROOT .'/core/modules/mrp/modules_mo.php'; /** diff --git a/htdocs/core/modules/mrp/mod_mo_standard.php b/htdocs/core/modules/mrp/mod_mo_standard.php index 6d392a6b74c..9546748387b 100644 --- a/htdocs/core/modules/mrp/mod_mo_standard.php +++ b/htdocs/core/modules/mrp/mod_mo_standard.php @@ -22,7 +22,7 @@ * \ingroup mrp * \brief File of class to manage MO numbering rules standard */ -require_once DOL_DOCUMENT_ROOT .'/core/modules/mrp/modules_mrp.php'; +require_once DOL_DOCUMENT_ROOT .'/core/modules/mrp/modules_mo.php'; /** * Class to manage MO numbering rules standard diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php index 822d6110c4b..69583f8c555 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php @@ -244,7 +244,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject } } - $dir = $conf->commande->multidir_output[$object->entity]; + $dir = $conf->commande->multidir_output[isset($object->entity)?$object->entity:1]; $objectref = dol_sanitizeFileName($object->ref); if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref; $file = $dir . "/" . $objectref . ".odt"; diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index c75c4bdc0d1..4752439c830 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -110,7 +110,7 @@ $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the inc $permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); $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 - +$upload_dir = $conf->mymodule->multidir_output[isset($object->entity)?$object->entity:1]; /* diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 0858ec44c6d..f5cdc89a1f7 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -92,8 +92,8 @@ class Mo extends CommonObject */ public $fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",), + 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1,), 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", 'showoncombobox'=>'1',), - 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>20, 'notnull'=>1, 'default'=>'1', 'index'=>1,), 'fk_bom' => array('type'=>'integer:Bom:bom/class/bom.class.php:0:t.status=1', 'filter'=>'active=1', 'label'=>'BOM', 'enabled'=>1, 'visible'=>1, 'position'=>33, 'notnull'=>-1, 'index'=>1, 'comment'=>"Original BOM",), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:1', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce",), 'qty' => array('type'=>'real', 'label'=>'QtyToProduce', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>1, 'comment'=>"Qty to produce",), diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 3b2e42b06b6..a881e23ff5a 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -97,6 +97,7 @@ $permissionnote = $user->rights->mrp->write; // Used by the include of actions_s $permissiondellink = $user->rights->mrp->write; // Used by the include of actions_dellink.inc.php $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php $permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); +$upload_dir = $conf->mrp->multidir_output[isset($object->entity)?$object->entity:1]; /*