Convert localized numeric extrafields value before inserting

- add 'double' case in insertExtraFields and updateExtraFields to to convert localized value using price2num()
This commit is contained in:
Jean-Marie Arsac 2018-09-11 14:57:31 +02:00
parent d011204624
commit 2f2dff8155

View File

@ -4851,6 +4851,9 @@ abstract class CommonObject
}
}
//dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
//dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
switch ($attributeType)
{
case 'int':
@ -4864,6 +4867,21 @@ abstract class CommonObject
$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')
{
@ -5058,6 +5076,9 @@ abstract class CommonObject
$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':
@ -5071,6 +5092,21 @@ abstract class CommonObject
$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=='')
{
$new_array_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')
{