Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo - Write null to numeric column

In Odoo/OpenERP 7, I have a nullable numeric column called balance

'balance': fields.float(string='Balance',digits=(20,2))

I am trying to use Python code to update None into the field

self.write(cr, uid, [1], { 'balance':None })

but, rather frustratingly, Python treats None the same as 0 so I end up with 0 in the DB instead of the expected Null.

Any pointers on how I can use the write command to store a null value?

like image 464
Daryl Van Sittert Avatar asked Jan 21 '15 14:01

Daryl Van Sittert


1 Answers

You can't: the Odoo ORM does not support null numeric values.

If you really need to distinguish an "empty" value from a zero value, you need a workaround: either use a string field (simpler, but needs additional checks to allow only number and it's harder to perform calculations) or use a second boolean field to mark empty values.

like image 111
Daniel Reis Avatar answered Nov 16 '22 07:11

Daniel Reis