Skip to content

Commit

Permalink
Merge pull request #9468 from jmarsac/numericextrafields9464
Browse files Browse the repository at this point in the history
Convert localized numeric extrafields value before inserting/updating
  • Loading branch information
eldy committed Sep 12, 2018
2 parents 2309635 + 345c249 commit 163bc55
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -4851,6 +4851,9 @@ function insertExtraFields($trigger='', $userused=null)
}
}

//dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
//dol_syslog("attributeType=".$attributeType, LOG_DEBUG);

switch ($attributeType)
{
case 'int':
Expand All @@ -4864,6 +4867,21 @@ function insertExtraFields($trigger='', $userused=null)
$new_array_options[$key] = null;
}
break;
case 'double':
$value = price2num($value);
if (!is_numeric($value) && $value!='')
{
dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
}
elseif ($value=='')
{
$new_array_options[$key] = null;
}
//dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
$new_array_options[$key] = $value;
break;
/*case 'select': // Not required, we chosed value='0' for undefined values
if ($value=='-1')
{
Expand Down Expand Up @@ -5058,6 +5076,9 @@ function updateExtraField($key, $trigger, $userused)
$attributeParam = $extrafields->attributes[$this->table_element]['param'][$key];
$attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key];

//dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
//dol_syslog("attributeType=".$attributeType, LOG_DEBUG);

switch ($attributeType)
{
case 'int':
Expand All @@ -5071,6 +5092,21 @@ function updateExtraField($key, $trigger, $userused)
$this->array_options["options_".$key] = null;
}
break;
case 'double':
$value = price2num($value);
if (!is_numeric($value) && $value!='')
{
dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
}
elseif ($value=='')
{
$this->array_options["options_".$key] = null;
}
//dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
$this->array_options["options_".$key] = $value;
break;
/*case 'select': // Not required, we chosed value='0' for undefined values
if ($value=='-1')
{
Expand Down

0 comments on commit 163bc55

Please sign in to comment.