Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
2014 Переглядів

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)

Related Posts Відповіді Переглядів Дія
1
бер. 22
2945
1
черв. 25
1494
3
лип. 25
3190
1
трав. 25
1320
1
трав. 25
1584