From 893ce55852a3320f90eee6fe293ad27cb8ea577e Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Thu, 19 Apr 2018 10:29:48 +0200 Subject: [PATCH] FIX: commonobject: don't require notnull field if default set --- htdocs/core/actions_addupdatedelete.inc.php | 4 ++-- htdocs/core/class/commonobject.class.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 6e1ddf8a796..ac9c80b37a5 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -62,7 +62,7 @@ if ($action == 'add' && ! empty($permissiontoadd)) if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field $object->$key=$value; - if ($val['notnull'] > 0 && $object->$key == '') + if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) { $error++; setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); @@ -117,7 +117,7 @@ if ($action == 'update' && ! empty($permissiontoadd)) if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field $object->$key=$value; - if ($val['notnull'] > 0 && $object->$key == '') + if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) { $error++; setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 11170a362f5..a1df5ca69ab 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6278,7 +6278,7 @@ abstract class CommonObject if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); - if ($this->fields[$key]['notnull'] == 1 && ! isset($values[$key])) + if ($this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) { $error++; $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);