Community: Framework mailing list archives

expert-framework@mail.odoo.com

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

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

A brief description of how depends works is provided in the api.py 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.one
            @api.depends('partner_id.name', 'partner_id.is_company')
            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

        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','partner_id.name','user_id.exten')
def _get_name(self, record):

Regards,
Atchuthan

On Sat, Sep 6, 2014 at 3:24 PM, Maxim Litnitskiy <litnimaxster@gmail.com> 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'],
                1,
                ),
                '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.one
@api.depends('exten_type', 'peer_id', 'pattern', 'custom_dialplan')
def _do_name(self):
    # code here

How can I specify other models??


@api.one
@api.depends('exten_type', 'peer_id', 'pattern', 'custom_dialplan')
@api.depends('res.partner.name') ???
def _do_name(self):
    # code here

Thanks.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe