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

Hello ! I need the store="true" to order my records with the value status that is get thanks to a compute method. The problem is that this value may change but is only known when the compute method is called.

So when i use store=false the value is always correct but i can't order my records with it because it isn't in the database.

How can i do ?


Thank you ! :)

Avatar
Discard
Best Answer

Hey,

'compute with store' is triggered by the decorator @api.depends(''). You can't trigger it by form load (in such a way only compute without store works)

As parameters you should specify definite fields. It is possible to define fields of reference fields (m2o, o2m, m2m).

E.g.

@api.multi

@api.depends('depend_1', 'depend_2.name', 'depend_3.name')

def _compute_myfield(self):

for object in self:

value = ''

if object.depend_1:

value += object.depend_1 

if object.depend_2 and object.depend_2.name:

value += object.depend_2.name

for item in object.depend_3:

if item.name:

value += item.name

object.myfield  =value  


myfield = fields.Char()

depend_1 = fields.Char()

depend_2 = fields.Many2one('some.class')

depend_3 = fields.Many2many('some.class.two')


So compute would be triggered in 3 cases:

  1. depend_1 is changed

  2. depend_2 or its name is changed

  3. any of depend_3 names is changed

It would happen before write/create. But order would be applied after those functions (since values should be saved in a database)

Avatar
Discard
Author Best Answer

Thank you very much ! Your explanation is great !

Avatar
Discard