跳至内容
菜单
此问题已终结
2 回复
1904 查看

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!

形象
丢弃
编写者 最佳答案

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) 
形象
丢弃
最佳答案

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

形象
丢弃
编写者

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)

相关帖文 回复 查看 活动
1
3月 22
2812
1
6月 25
1128
3
7月 25
2862
1
5月 25
1067
1
5月 25
1331