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

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.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
12月 24
6149
3
8月 24
7020
4
7月 24
41388
5
4月 23
99275
3
11月 22
4435