From c0b0d5484cd002b1cb559e9e1a0122df8af0987f Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 19 Jan 2019 17:14:56 +0100 Subject: [PATCH 1/2] Compute value of computed extrafield on fetch, not on show --- htdocs/core/class/commonobject.class.php | 5 +++++ htdocs/core/class/extrafields.class.php | 8 -------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 676e76fe16a..877bb2c5c93 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4744,6 +4744,11 @@ abstract class CommonObject //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); $this->array_options["options_".$key]=$this->db->jdate($value); } + // If field is a computed field, value must become result of compute + else if (! empty($extrafields) && !empty($extrafields->attributes[$this->table_element]['computed'][$key])) + { + $this->array_options["options_".$key] = dol_eval($extrafields->attributes[$this->table_element]['computed'][$key], 1, 0); + } else { $this->array_options["options_".$key]=$value; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 48eabbefe9e..596486654fa 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1468,14 +1468,6 @@ class ExtraFields if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. - // If field is a computed field, value must become result of compute - if ($computed) - { - // Make the eval of compute string - //var_dump($computed); - $value = dol_eval($computed, 1, 0); - } - $showsize=0; if ($type == 'date') { From 23438b1f48e59ce708d970ce6d5abca26e766004 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 21 Jan 2019 14:40:33 +0100 Subject: [PATCH 2/2] Compute extrafields after having set all others --- htdocs/core/class/commonobject.class.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 92f32393df7..3ba0bf34e58 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4852,11 +4852,6 @@ abstract class CommonObject //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); $this->array_options["options_".$key]=$this->db->jdate($value); } - // If field is a computed field, value must become result of compute - else if (! empty($extrafields) && !empty($extrafields->attributes[$this->table_element]['computed'][$key])) - { - $this->array_options["options_".$key] = dol_eval($extrafields->attributes[$this->table_element]['computed'][$key], 1, 0); - } else { $this->array_options["options_".$key]=$value; @@ -4865,6 +4860,14 @@ abstract class CommonObject //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); } } + + // If field is a computed field, value must become result of compute + foreach ($tab as $key => $value) { + if (! empty($extrafields) && !empty($extrafields->attributes[$this->table_element]['computed'][$key])) + { + $this->array_options["options_".$key] = dol_eval($extrafields->attributes[$this->table_element]['computed'][$key], 1, 0); + } + } } $this->db->free($resql);