2
0
forked from Wavyzz/dolibarr

FIX missing setup of extrafields for MO

FIX all extrafields cleared after update of one of them
FIX Update of extrafields date
FIX Update of extrafiels on draft object
FIX Sql type
Fix trans on BOM
This commit is contained in:
Laurent Destailleur
2020-07-04 16:14:53 +02:00
parent 9912ffd555
commit 1c19c97cf2
15 changed files with 399 additions and 9 deletions

View File

@@ -0,0 +1,113 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/bom_extrafields.php
* \ingroup bom
* \brief Page to setup extra fields of BOM
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load translation files required by the page
$langs->loadLangs(array('mrp', 'admin'));
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
$action = GETPOST('action', 'alpha');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'bom_bom';
if (!$user->admin) accessforbidden();
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
llxHeader('', $langs->trans("BOMsSetup"), $help_url);
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("BOMsSetup"), $linkback, 'title_setup');
$head = bomAdminPrepareHead(null);
dol_fiche_head($head, 'bom_extrafields', $langs->trans("ExtraFields"), -1, 'account');
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
dol_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
}
/*
* Creation of an optional field
*/
if ($action == 'create')
{
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
/*
* Edition of an optional field
*/
if ($action == 'edit' && !empty($attrname))
{
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View File

@@ -0,0 +1,113 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/mrp_extrafields.php
* \ingroup mrp
* \brief Page to setup extra fields of MOs
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load translation files required by the page
$langs->loadLangs(array('mrp', 'admin'));
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
$action = GETPOST('action', 'alpha');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'mrp_mo';
if (!$user->admin) accessforbidden();
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
llxHeader('', $langs->trans("MrpSetupPage"), $help_url);
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("MrpSetupPage"), $linkback, 'title_setup');
$head = mrpAdminPrepareHead(null);
dol_fiche_head($head, 'mrp_extrafields', $langs->trans("ExtraFields"), -1, 'account');
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
dol_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
}
/*
* Creation of an optional field
*/
if ($action == 'create')
{
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
/*
* Edition of an optional field
*/
if ($action == 'edit' && !empty($attrname))
{
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View File

@@ -333,8 +333,10 @@ class BOM extends CommonObject
public function fetch($id, $ref = null) public function fetch($id, $ref = null)
{ {
$result = $this->fetchCommon($id, $ref); $result = $this->fetchCommon($id, $ref);
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines(); if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
$this->calculateCosts(); $this->calculateCosts();
return $result; return $result;
} }

View File

@@ -41,6 +41,11 @@ function bomAdminPrepareHead()
$head[$h][2] = 'settings'; $head[$h][2] = 'settings';
$h++; $h++;
$head[$h][0] = dol_buildpath("/admin/bom_extrafields.php", 1);
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'bom_extrafields';
$h++;
/*$head[$h][0] = DOL_URL_ROOT."/bom/admin/about.php"; /*$head[$h][0] = DOL_URL_ROOT."/bom/admin/about.php";
$head[$h][1] = $langs->trans("About"); $head[$h][1] = $langs->trans("About");
$head[$h][2] = 'about'; $head[$h][2] = 'about';

View File

@@ -96,6 +96,12 @@ if ($action == 'add' && !empty($permissiontoadd))
} }
} }
// Fill array 'array_options' with data from add form
if (!$error) {
$ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) $error++;
}
if (!$error) if (!$error)
{ {
$result = $object->create($user); $result = $object->create($user);
@@ -174,6 +180,12 @@ if ($action == 'update' && !empty($permissiontoadd))
} }
} }
// Fill array 'array_options' with data from add form
if (!$error) {
$ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) $error++;
}
if (!$error) if (!$error)
{ {
$result = $object->update($user); $result = $object->update($user);
@@ -201,7 +213,14 @@ if ($action == "update_extras" && !empty($permissiontoadd))
$attributekey = GETPOST('attribute', 'alpha'); $attributekey = GETPOST('attribute', 'alpha');
$attributekeylong = 'options_'.$attributekey; $attributekeylong = 'options_'.$attributekey;
if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
// This is properties of a date
$object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
//var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
} else {
$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha'); $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha');
}
$result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user); $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
if ($result > 0) if ($result > 0)

View File

@@ -47,7 +47,9 @@ if (($id > 0 || (!empty($ref) && !in_array($action, array('create', 'createtask'
setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors'); setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
} }
} }
else setEventMessages($object->error, $object->errors, 'errors'); else {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = ''; $action = '';
} }
} }

View File

@@ -8114,6 +8114,11 @@ abstract class CommonObject
if ($obj) if ($obj)
{ {
$this->setVarsFromFetchObj($obj); $this->setVarsFromFetchObj($obj);
// Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals();
return $this->id; return $this->id;
} }
else else

View File

@@ -148,7 +148,10 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]
if ($object->element == 'delivery') $permok = $user->rights->expedition->livraison->creer; if ($object->element == 'delivery') $permok = $user->rights->expedition->livraison->creer;
if ($object->element == 'productlot') $permok = $user->rights->stock->creer; if ($object->element == 'productlot') $permok = $user->rights->stock->creer;
if ($object->element == 'facturerec') $permok = $user->rights->facture->creer; if ($object->element == 'facturerec') $permok = $user->rights->facture->creer;
if (($object->statut == 0 || !empty($extrafields->attributes[$object->table_element]['alwayseditable'][$key])) if ($object->element == 'mo') $permok = $user->rights->mrp->write;
$isdraft = ((isset($object->statut) && $object->statut == 0) || (isset($object->status) && $object->status == 0));
if (($isdraft || !empty($extrafields->attributes[$object->table_element]['alwayseditable'][$key]))
&& $permok && $enabled != 5 && ($action != 'edit_extras' || GETPOST('attribute') != $key) && $permok && $enabled != 5 && ($action != 'edit_extras' || GETPOST('attribute') != $key)
&& empty($extrafields->attributes[$object->table_element]['computed'][$key])) && empty($extrafields->attributes[$object->table_element]['computed'][$key]))
{ {

View File

@@ -81,6 +81,8 @@ delete from llx_const where name in ('PROJECT_HIDE_TASKS', 'MAIN_BUGTRACK_ENABLE
-- For v12 -- For v12
ALTER TABLE llx_bom_bom MODIFY COLUMN duration double(24,8);
ALTER TABLE llx_prelevement_bons ADD COLUMN type varchar(16) DEFAULT 'debit-order'; ALTER TABLE llx_prelevement_bons ADD COLUMN type varchar(16) DEFAULT 'debit-order';
ALTER TABLE llx_ecm_files MODIFY COLUMN src_object_type varchar(64); ALTER TABLE llx_ecm_files MODIFY COLUMN src_object_type varchar(64);

View File

@@ -0,0 +1,113 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/modulebuilder/tempalte/admin/myobject_extrafields.php
* \ingroup mymodule
* \brief Page to setup extra fields of myobject
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/bom.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load translation files required by the page
$langs->loadLangs(array('mrp@mrp', 'admin'));
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
$action = GETPOST('action', 'alpha');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'mymodule_myobject'; //Must be the $table_element of the class that manage extrafield
if (!$user->admin) accessforbidden();
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
llxHeader('', $langs->trans("MyModuleSetup"), $help_url);
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("MyModuleSetup"), $linkback, 'title_setup');
$head = mymoduleAdminPrepareHead(null);
dol_fiche_head($head, 'myobject_extrafields', $langs->trans("MyObjectExtraFields"), -1, 'account');
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
dol_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
}
/*
* Creation of an optional field
*/
if ($action == 'create')
{
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
/*
* Edition of an optional field
*/
if ($action == 'edit' && !empty($attrname))
{
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View File

@@ -33,12 +33,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
class MyObject extends CommonObject class MyObject extends CommonObject
{ {
/** /**
* @var string ID to identify managed object * @var string ID to identify managed object.
*/ */
public $element = 'myobject'; public $element = 'myobject';
/** /**
* @var string Name of table without prefix where object is stored * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
*/ */
public $table_element = 'mymodule_myobject'; public $table_element = 'mymodule_myobject';

View File

@@ -39,6 +39,14 @@ function mymoduleAdminPrepareHead()
$head[$h][1] = $langs->trans("Settings"); $head[$h][1] = $langs->trans("Settings");
$head[$h][2] = 'settings'; $head[$h][2] = 'settings';
$h++; $h++;
/*
$head[$h][0] = dol_buildpath("/mymodule/admin/myobject_extrafields.php", 1);
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'myobject_extrafields';
$h++;
*/
$head[$h][0] = dol_buildpath("/mymodule/admin/about.php", 1); $head[$h][0] = dol_buildpath("/mymodule/admin/about.php", 1);
$head[$h][1] = $langs->trans("About"); $head[$h][1] = $langs->trans("About");
$head[$h][2] = 'about'; $head[$h][2] = 'about';

View File

@@ -40,6 +40,11 @@ function mrpAdminPrepareHead()
$head[$h][2] = 'settings'; $head[$h][2] = 'settings';
$h++; $h++;
$head[$h][0] = dol_buildpath("/admin/mrp_extrafields.php", 1);
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'mrp_extrafields';
$h++;
// Show more tabs from modules // Show more tabs from modules
// Entries must be declared in modules descriptor with line // Entries must be declared in modules descriptor with line
//$this->tabs = array( //$this->tabs = array(

View File

@@ -667,7 +667,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED)
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes">'.$langs->trans("Re-Open").'</a>'."\n"; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes">'.$langs->trans("ReOpen").'</a>'."\n";
} }
} }

View File

@@ -127,7 +127,7 @@ if (empty($reshook)) {
{ {
if ($caneditperms) if ($caneditperms)
{ {
if (!$_POST["nom"]) { if (! GETPOST("nom", "nohtml")) {
setEventMessages($langs->trans("NameNotDefined"), null, 'errors'); setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
$action = "create"; // Go back to create page $action = "create"; // Go back to create page
} else { } else {