Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
6300 Widoki

Hi Oddoers,

I was reading the documentation about the depends decorator of the ORM API and I don't understand the following statement written in the documentation:

openerp.api.depends(*args)
One may also pass a single function as argument. In that case, the dependencies are given by calling the function with the field's model.

I suposse that it means that I can use a name function as an argument in *args, as that this function returns the dependencies.

For example:

pname = fields.Char(compute='_compute_pname')

@api.one
@api.depends(my_function)
def _compute_pname(self):
    if self.partner_id.is_company:
        self.pname = (self.partner_id.name or "").upper()
    else:
        self.pname = self.partner_id.name

def my_function(self): return ???

What should my_function return?. Should it return the dependencies into a list or into another kind of data structure type?.


Awatar
Odrzuć
Najlepsza odpowiedź

Just return the field names that your computed fields depends on as a list of strings. 

Quoting From your example 

pname = fields.Char(compute='_compute_pname')

@api.one
@api.depends(lambda self: self.my_function())
def _compute_pname(self):
    if self.partner_id.is_company:
        self.pname = (self.partner_id.name or "").upper()
    else:
        self.pname = self.partner_id.namedef my_function(self):
 
def my_function(self):
    return ['partner_id.name']
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
mar 17
3398
2
kwi 18
12477
2
gru 22
14741
1
lis 21
4850
0
sty 21
2241