Skip to Content
Menu
This question has been flagged
2 Replies
1975 Views

I have a float field in a wizard.

In the wizard .py:


_columns = {'p1': fields.float('P1', digits=(16, 2))}

When I open the wizard, I can see 0,00 into the input field, but when I read data from the wizard, I get "False":


x = self.datas[1]['p1'] # Returns False, not 0.0


wiz = self.browse(cursor, uid, ids[0], context)
x = wiz.p1 # Also returns False

Avatar
Discard
Author Best Answer

Thank you, Anthony.

This error only occurs when the value is 0.0. If the value is 1.0, it works fine.

I'm creating the field as float:

_columns = {'p1': fields.float('P1', digits=(16, 2))}

How could I get that the 0.0 value won't be converted to boolean? With integer (0) value, it doesn't occur.

Avatar
Discard

could you show me what a field_get return on your model please ? With "string", "type" selectors ?

Author

self.fields_get(cursor, uid, 'p1')['p1']['type'] returns "float", but self.datas[1]['p1'] is False. It's strange.

Author

Anthony, do you have any idea with this information? Thank you in advance :)

Best Answer

I think it's just a python problem.

In python, 0 <=> False, so 0.00 <=> 0 <=> False

In an Odoo field you have types stored like "many2one" or "float", "monetary" etc. Maybe you can use it for convert in right type.

Also try to store 0.01 and 0.99 and check if the values become booleans to.

In this case it's another problem, otherwise it's just python which optimizes the value to take less memory

Avatar
Discard