跳至內容
選單
此問題已被標幟
2 回覆
1956 瀏覽次數

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
2882
1
6月 25
1220
3
7月 25
2965
1
5月 25
1146
1
5月 25
1416