Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Problems with new api function inheritance

By
Jesús Ventosinos
on 1/27/15, 5:10 AM 2,344 views

I am trying to inherit email.template function with the signature:

def generate_email_batch(self, cr, uid, template_id, res_ids, context=None, fields=None):

But when my custom function calls super fails, i think this is because the function not have ids and "fields" are after  the context

my module code:

from openerp import models, fields, api


class EmailTemplate(models.Model):

    _inherit = 'email.template'

    @api.multi
    def generate_email_batch(self, res_ids, fields=None):
        res = super(EmailTemplate,self).generate_email_batch(res_ids, fields)

 

if i change the signature of original function to:

def generate_email_batch(self, cr, uid, ids, res_ids=None, fields=None, context=None):

i have no problem to inherit in new api.

I'm doing something wrong or the new api can't inherit functions with the ids field with another name and field after context?

Thanks you Ivan, but the problem with the context persist, i do not know if the problem is because the argument fields is after context or is another problem with my code. File "/opt/openerp/buildout_projects/parts/odoo/openerp/api.py", line 462, in new_api result = method(self._model, cr, uid, *args, **kwargs) TypeError: generate_email_batch() got multiple values for keyword argument 'context' @api.model def generate_email_batch(self, template_id, res_ids, fields=None): res = super(EmailTemplate,self).generate_email_batch(template_id, res_ids, fields)

Jesús Ventosinos
on 1/27/15, 6:26 AM

change it to super(EmailTemplate,self).generate_email_batch(template_id, res_ids, fields=fields). If fields is specified without name it will fill into the place of context, which is the next argument. Since @api.model also adds context=context, it complains about multiple values for keyword argument 'context'. - I think.

Ivan
on 1/27/15, 6:56 AM
1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/27/15, 5:26 AM

@api.multi implies that there will be ids in the arguments passed if the original method is defined in old API signature.  If template_id is the single id of model that owns generate_email_batch, use @api.one decorator.  If it will be passed as argument, use @api.model decorator.

This slide provide a good overview of the decorators compared to the old API: http://www.slideshare.net/openobject/odoo-from-v7-to-v8-the-new-api

Ivan
on 1/27/15, 5:28 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/27/15, 5:10 AM
Seen: 2344 times
Last updated: 3/16/15, 8:10 AM