Daryl Van Sittert
Daryl Van Sittert

Reputation: 877

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?

Upvotes: 10

Views: 5814

Answers (1)

Daniel Reis
Daniel Reis

Reputation: 13342

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.

Upvotes: 9

Related Questions