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

I have a custom model with an init view for _auto = False when I access the list view I got wrong data in a Many2one field analytic_line_type_id ! Debugging results:

 > /odoo/odoo-server/odoo/models.py(3247)_read_format()
-> for record, vals in data:
(Pdb) record[name], record.analytic_line_type_id,  self.env[self._name].search_read([('id','=',record.id)],['analytic_line_type_id'])[0]
(account.analytic.line.type(1,), account.analytic.line.type(1,), {'id': 9057, 'analytic_line_type_id': (15, "Temps d'assemblage atelier")})
(Pdb) record[name], record.analytic_line_type_id,  self.env[self._name].search_read([('id','=',record.id)],['analytic_line_type_id'])[0]
(account.analytic.line.type(15,), account.analytic.line.type(15,), {'id': 9057, 'analytic_line_type_id': (15, "Temps d'assemblage atelier")})
(Pdb) record[name], record.analytic_line_type_id,  self.env[self._name].search_read([('id','=',record.id)],['analytic_line_type_id'])[0]
(account.analytic.line.type(15,), account.analytic.line.type(15,), {'id': 9057, 'analytic_line_type_id': (15, "Temps d'assemblage atelier")})

Why record.analytic_line_type is not correct in the first call ?
As you can see the search_read value is different to direct access to the field!

Avatar
Discard
Author Best Answer

in the sql view the id may changes, I added the field on the order by of the row_number()

row_number() OVER ( order by analytic_line_type_id) 
Avatar
Discard
Best Answer

HI,
Here you cannot trust the id of the record as it is a dynamic one and keeps changing when the model/view is loaded. Try using search_read orm method or give a id value to the records which cannot be changed.



Thanks

Avatar
Discard
Author

Hello Niyas,
thank you for reminding me about that.
I access the values from the list view, the data in the list is not correct, but if I group by that field I got the right value returned by search_read!
everything works fine till now, when the view had more data I got this behaviors.
after looking deeply in the sql view I added the field analytic_line_type_id on the row_number() OVER ( order by analytic_line_type_id)

Related Posts Replies Views Activity
1
Mar 22
2758
1
Jun 25
1023
3
Jul 25
2753
1
May 25
995
1
May 25
1184