diff --git a/htdocs/core/actions_fetchobject.inc.php b/htdocs/core/actions_fetchobject.inc.php
index 520d3c2d6da..a4c6b80548d 100644
--- a/htdocs/core/actions_fetchobject.inc.php
+++ b/htdocs/core/actions_fetchobject.inc.php
@@ -30,7 +30,7 @@
if (($id > 0 || (! empty($ref) && ! in_array($action, array('create','createtask')))) && empty($cancel))
{
- $ret = $object->fetch($id,$ref);
+ $ret = $object->fetch($id, $ref);
if ($ret > 0)
{
$object->fetch_thirdparty();
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 80eb7d31cfb..f0146b2cb03 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -4905,7 +4905,7 @@ abstract class CommonObject
*
* @param stdClass $obj Contain data of object from database
*/
- private function set_vars_by_db(&$obj)
+ private function setVarsFromFetchObj(&$obj)
{
foreach ($this->fields as $field => $info)
{
@@ -4922,7 +4922,8 @@ abstract class CommonObject
}
elseif($this->isInt($info))
{
- $this->{$field} = (int) $obj->{$field};
+ if ($field == 'rowid') $this->id = (int) $obj->{$field};
+ else $this->{$field} = (int) $obj->{$field};
}
elseif($this->isFloat($info))
{
@@ -4982,6 +4983,7 @@ abstract class CommonObject
$fieldvalues = $this->set_save_query();
if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
+ if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
unset($fieldvalues['rowid']); // We suppose the field rowid is reserved field for autoincrement field.
$keys=array();
@@ -5048,8 +5050,10 @@ abstract class CommonObject
// Load source object
$object->fetchCommon($fromid);
- // Reset object
- $object->id = 0;
+ // Reset some properties
+ unset($object->id);
+ unset($object->fk_user_creat);
+ unset($object->import_key);
// Clear fields
$object->ref = "copy_of_".$object->ref;
@@ -5088,7 +5092,7 @@ abstract class CommonObject
{
if (empty($id) && empty($ref)) return false;
- $sql = 'SELECT '.$this->get_field_list().', date_creation, tms';
+ $sql = 'SELECT '.$this->get_field_list();
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
if(!empty($id)) $sql.= ' WHERE rowid = '.$id;
@@ -5101,12 +5105,7 @@ abstract class CommonObject
{
if ($obj)
{
- $this->id = $id;
- $this->set_vars_by_db($obj);
-
- $this->date_creation = $this->db->idate($obj->date_creation);
- $this->tms = $this->db->idate($obj->tms);
-
+ $this->setVarsFromFetchObj($obj);
return $this->id;
}
else
diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php
index 756db6e8e9c..adec8cfbf86 100644
--- a/htdocs/modulebuilder/template/class/myobject.class.php
+++ b/htdocs/modulebuilder/template/class/myobject.class.php
@@ -55,7 +55,7 @@ class MyObject extends CommonObject
/**
* @var string String with name of icon for myobject
*/
- public $picto = 'myobject';
+ public $picto = 'myobject@mymodule';
/**
diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php
index 4151553f2bd..1101d9110bc 100644
--- a/htdocs/modulebuilder/template/myobject_card.php
+++ b/htdocs/modulebuilder/template/myobject_card.php
@@ -61,6 +61,7 @@ $langs->loadLangs(array("mymodule","other"));
// Get parameters
$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
@@ -130,7 +131,7 @@ if (empty($reshook))
{
foreach ($object->fields as $key => $val)
{
- if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields
+ if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
$object->$key=GETPOST($key,'alpha');
if ($val['notnull'] && $object->$key == '')
@@ -170,7 +171,7 @@ if (empty($reshook))
foreach ($object->fields as $key => $val)
{
$object->$key=GETPOST($key,'alpha');
- if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue;
+ if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
if ($val['notnull'] && $object->$key == '')
{
$error++;
@@ -263,12 +264,14 @@ if ($action == 'create')
print '
'."\n";
@@ -294,8 +297,17 @@ if (($id || $ref) && $action == 'edit')
dol_fiche_head();
print '';
dol_fiche_end();
@@ -405,9 +417,18 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '