diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3b9a4771ba0..7294d77aa07 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5187,7 +5187,10 @@ abstract class CommonObject { foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) { - $sql.=",".$tmpkey; + if (! isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) // If field not already added previously + { + $sql.=",".$tmpkey; + } } } $sql .= ") VALUES (".$this->id; @@ -5213,8 +5216,11 @@ abstract class CommonObject { foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) { - if (in_array($tmpval, array('int', 'double'))) $sql.=", 0"; - else $sql.=", ''"; + if (! isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) // If field not already added previously + { + if (in_array($tmpval, array('int', 'double'))) $sql.=", 0"; + else $sql.=", ''"; + } } } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 4795eedc219..f7b0edaa0f1 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -877,7 +877,7 @@ class ExtraFields { if ($tab->entity != 0 && $tab->entity != $conf->entity) { - // This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field + // This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field without default value if ($tab->fieldrequired && is_null($tab->fielddefault)) { $this->attributes[$tab->elementtype]['mandatoryfieldsofotherentities'][$tab->name]=$tab->type;