Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
1861 Visualizações

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
Cancelar
Autor Melhor resposta

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
Cancelar
Melhor resposta

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
Cancelar
Autor

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)

Publicações relacionadas Respostas Visualizações Atividade
1
mar. 22
2767
1
jun. 25
1052
3
jul. 25
2792
1
mai. 25
1014
1
mai. 25
1252