onchange dysfunction in Odoo 12 when name of a computed field is "length"
I spent a lot of time understanding the behaviour of @api.onchange in some of my forms. I found on my own that it was due to the name "length" given to a computed field. As example, here is a very simple model for words, with a field that computes the length and an onchange function to ensure that the words are recorded in uppercase.
_name = 'mymodule.words'
word = fields.Text('Word')
length = fields.Integer('Length', compute='_compute_length')
for record in self:
if not record.word: record.word = ""
record.length = len(record.word)
self.word = self.word.upper()
In odoo12, using this model, the onchange function that shoud convert words to uppercase is not working as expected (very erratic behaviour).
I just replaced "length" as field name by the french word "longueur". Then, onchange works perfectly.
Should it be reported as a bug ? I believe so. Until it is fixed by Odoo, "length" should be avoided as field name, although I haven't seen in any Odoo documentation that it was a reserved name.