diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index af1b077b020..b82970baa97 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9736,6 +9736,19 @@ abstract class CommonObject $this->{$key} = $value; } } + + // Force values to default values when known + foreach ($this->fields as $key => $value) { + // If fields are already set, do nothing + if (array_key_exists($key, $fields)) { + continue; + } + + if (!empty($value['default'])) { + $this->$key = $value['default']; + } + } + return 1; } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 6f346179aa8..d9b8918e4b2 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -2080,8 +2080,12 @@ class ExtraFields || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) { //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; - // Field is not defined. We mark this as a problem. We may fix it later if there is a default value and $todefaultifmissing is set. + // Field is not defined. We mark this as an error. We may fix it later if there is a default value and $todefaultifmissing is set. + $nofillrequired++; + if (!empty($this->attributes[$object->table_element]['langfile'][$key])) { + $langs->load($this->attributes[$object->table_element]['langfile'][$key]); + } $error_field_required[$key] = $langs->transnoentitiesnoconv($value); } } diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 447988c5aab..7558fd890ce 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -3075,7 +3075,7 @@ class SupplierProposalLine extends CommonObjectLine $sql .= " ".price2num($this->localtax2_tx).","; $sql .= " '".$this->db->escape($this->localtax1_type)."',"; $sql .= " '".$this->db->escape($this->localtax2_type)."',"; - $sql .= " ".(!empty($this->subprice) ? price2num($this->subprice, 'MU') : "null").","; + $sql .= " ".price2num($this->subprice, 'MU') .","; $sql .= " ".((float) $this->remise_percent).","; $sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").","; $sql .= " ".price2num($this->total_ht, 'MT').",";