From a1016d79a2eef10e8c26fe56eb1a61b7d25f3b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 1 Nov 2020 20:33:06 +0100 Subject: [PATCH 1/2] initSpecimenCommon --- htdocs/core/class/commonobject.class.php | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 62863ffb1d1..0cbff14cf0a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8285,22 +8285,31 @@ abstract class CommonObject * Initialise object with example values * Id must be 0 if object instance is a specimen * - * @return void + * @return int */ public function initAsSpecimenCommon() { global $user; $this->id = 0; - if (array_key_exists('label', $this->fields)) $this->label = 'This is label'; - if (array_key_exists('note_public', $this->fields)) $this->note_public = 'Public note'; - if (array_key_exists('note_private', $this->fields)) $this->note_private = 'Private note'; - if (array_key_exists('date_creation', $this->fields)) $this->date_creation = (dol_now() - 3600 * 24); - if (array_key_exists('date_modification', $this->fields)) $this->date_modification = (dol_now() - 3600 * 24); - if (array_key_exists('fk_user_creat', $this->fields)) $this->fk_user_creat = $user->id; - if (array_key_exists('fk_user_modif', $this->fields)) $this->fk_user_modif = $user->id; - if (array_key_exists('date', $this->fields)) $this->date = dol_now(); - // ... + $this->specimen = 1; + $fields = array( + 'label' => 'This is label', + 'ref' => 'ABCD1234', + 'description' => 'This is a description', + 'qty' => 123.12, + 'note_public' => 'Public note', + 'note_private' => 'Private note', + 'date_creation' => (dol_now() - 3600 * 24), + 'date_modification' => (dol_now() - 3600 * 24), + 'fk_user_creat' => $user->id, + 'fk_user_modif' => $user->id, + 'date' => dol_now(), + ); + foreach ($fields as $key => $value) { + if (array_key_exists($key, $this->fields)) $this->{$key} = $value; + } + return 1; } From 878b8f25debce63adefc35da54bc234d5732fc08 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Nov 2020 09:29:26 +0100 Subject: [PATCH 2/2] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0cbff14cf0a..27309ac811e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8300,7 +8300,7 @@ abstract class CommonObject 'qty' => 123.12, 'note_public' => 'Public note', 'note_private' => 'Private note', - 'date_creation' => (dol_now() - 3600 * 24), + 'date_creation' => (dol_now() - 3600 * 48), 'date_modification' => (dol_now() - 3600 * 24), 'fk_user_creat' => $user->id, 'fk_user_modif' => $user->id,