I found @api.depends() can also pass a function to set depends.
But when should I use this feature, can anyone give a example?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I found @api.depends() can also pass a function to set depends.
But when should I use this feature, can anyone give a example?
Hi,
in depends api, we add fields that will trigger the function. Imagine you have a list of fields to include in depends.
you can easily put them in a function and call it inside of api.depends.
Ex:
def _get_dependencies(self):
return ['Field1', 'Field1.Field2', 'Field1.Field3', 'Field3',
'Field4', 'Field4.Field1', 'Field5','Field6','Field7','Field8','Field9','Field9.Field2','Field9.Field6']
and then :
@api.multi
@api.depends(_get_dependencies)
def _compute_my_field(self): //....
That is to say, with a function, you return the fields that you need, to trigger the depends function.
my case :
based on the connected user's profile, some fields should trigger the compute function.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
3
Aug 24
|
5503 | ||
|
4
Jul 24
|
38817 | ||
Default value in form view
Solved
|
|
5
Apr 23
|
93737 | |
|
3
Nov 22
|
2957 | ||
|
3
Aug 22
|
3040 |