[Vtigercrm-developers] Saving object with Currency Field - obscured value

Stencel, Maciej m.stencel at opensaas.pl
Mon Jan 20 10:36:58 GMT 2014


Hi,

I have a question regarding weird behaviour of currency field value after
save.

In our CMR we have thousand separator as "." and decimal separator as ",".

When creating or editing record I use CRMEntity class. I have added to
Potentials "saldo" with currency field type.

When creating or editing Potential i have to convert normal float value to
user displayed type (for example not 1000.00 but 1.000,00). I use for that
function from Currency Field:

CurrencyField::convertToUserFormat( $money );

If I won't use that function the value will be obscured for example from
1000.00 it will remove the decimal separator as unknown character (in
settings we have coma as decimal separator) making it 100000 . 00.

When Im creating or editing object and I add or change this value it's no
problem - I remember to use mentioned function.

But later when for example im editing one field from Potentials and save
the object, my "saldo" field is changed. It's as if the object gets the
value from db (normal float value) and when saving it wants the value
formated with dot as thousand separator and coma as decimal separator. It
finds always just float value and so everytime I edit the object the
currency field value is changed.

To fix it, when Im editing object I have to remember to reassign currency
field value with formatted value, for example:

$object->column_fields['saldo'] = CurrencyField::convertToUserFormat(
$object->column_fields['saldo'] );

I think that object should detect itself if the value isn't formatted
correctly or if its normal float and convert it properly. Because it's
pointless to reassign currency field value everytime I'm editing object
even if the value doesnt change...

*Z poważaniem / Best regards*

*Maciej Stencel*
*Tel: +48 884-997-123*

*m.stencel at opensaas.pl <m.stencel at opensaas.pl>www.OpenSaaS.pl
<http://www.opensaas.pl/>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140120/7beabd01/attachment.html>


More information about the vtigercrm-developers mailing list