Technical mailing list archives

Re: @api.depends cannot be set for tracking other module fields?

Atchuthan - Technical Consultant, Sodexis Inc
- 09/11/2014 03:32:19
Hi Maxim,

A brief description of how depends works is provided in the file of Version 8

def depends(*args):
    """ Return a decorator that specifies the field dependencies of a "compute"
        method (for new-style function fields). Each argument must be a string
        that consists in a dot-separated sequence of field names::

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

            @api.depends('', 'partner_id.is_company')
            def _compute_pname(self):
                if self.partner_id.is_company:
                    self.pname = ( or "").upper()
                    self.pname =

        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.
    if args and callable(args[0]):
        args = args[0]
    return lambda method: decorate(method, '_depends', args)

So, First we need to create a many2one field that links to this object 'astpbx.exten' named 'extension_id'

@depends('extension_id.exten_type', 'extension_id.peer_jd', 'extension_id.pattern', 'extension_id.custom_dialplan','','user_id.exten')
def _get_name(self, record):


On Sat, Sep 6, 2014 at 3:24 PM, Maxim Litnitskiy <> wrote:
Hi dear developers!
I have a question regarding new api.
Seems we lost a good piese of functionality with new @api.depends.
Here is the example

Old api:

    _columns = {
        'name': fields.function(_get_name, method=True, type='char', string='Name', store={
            'astpbx.exten': (
                lambda self, cr, uid, ids, c={}: ids,
                ['exten_type', 'peer_id', 'pattern', 'custom_dialplan'],
                'res.partner': (_get_partner_user_exten, ['name'], 1),
                'res.users': (_get_user_exten, ['exten'], 1),

I redefine column 'name' when partner name is changed and also when my model's fields are changed.

Now how can I move that code to new api?
@api.depends('exten_type', 'peer_id', 'pattern', 'custom_dialplan')
def _do_name(self):
    # code here

How can I specify other models??
@api.depends('exten_type', 'peer_id', 'pattern', 'custom_dialplan')
@api.depends('') ???
def _do_name(self):
    # code here


Post to: