This question has been flagged
13 Replies
31310 Views

Hi i am new to openerp i need help in calling super methods

Any one help me with simple example

Avatar
Discard
Best Answer


# this one is working fine in v13

class YourModel(models.Model):

    _inherit = "your.model"
    #_inherit = "pos.config"

@api.model
def write(self, vals):
    super(models.Model, self).write(vals) #--call directly orm's method
    super(PosConfig, self).write(vals) #--call parent class's method, you can also use, "super().write(vals)" in v13 no need to give class name and self

Avatar
Discard
Best Answer

super(your_crazy_modelname,self).name_of_method_you_want_to_call(cr,uid,ids, context=context)

Or something like this


class inherit_something(models.Model):      
_inherit = 'report'
def some_thing(self,cr,uid,ids,report_name,context=None):
super(inherit_something,self).get_pdf(cr,uid,ids,report_name, context=context,data = data)
Avatar
Discard
Author

Thanks Dairidi

Best Answer

Hy Karthik,

Just for your information, if you are trying  eliminate of calling super method (for ORM Methods), its because sometimes it may raise exception if you call super after your modification for ORM Methods.

instead of this -> super(stock_move, self).write(cr, uid, ids, vals, context=context)

you can give-> osv.osv.write(self, cr, uid, ids, vals, context=context)

This will call directly write function of ORM...

Hope this helps....

 

Avatar
Discard

well, but I'll be thankful if you gave a reason for this, I need to understand your reply.

If you are overriding ORM method you have to call super function and it will raise exception if you change the function for your need, at that time you can use this.

But I do overriding the 'write' and 'create' so much and nothing was raised on my face. Could you pls feed me with a code that caused the problem you mean and the code how you resolved.

we will not face any error if we are adding some small codes or change and we call super, the problem is when we want to change the original code to suit our need and then after that if we call super method it may raise some error, it is because some time the old logic and new logic doesn’t match. At that time we don't need to call the super method and we need to eliminate that. It may occur for some bigger modifications. I faced this when I made modifications on HR Module. Sorry I can't provide full code here. if you need more details you can e-mail me: baijuks@hotmail.com

I got your idea, thx for clarification.

Best Answer


class test(osv.osv):

.

.

.

def unlink(self, cr, uid, ids, context=None):

#Your code goes here.

return super(test, self).unlink(cr, uid, ids, context=context)

Avatar
Discard
Author

Thank you Dep.

Best Answer

hii Karthik,

hope this will help you.

class MODEL_NAME(osv.Model):

    def ORM_METHOD_NAME(self, cr, uid,(List of required parameters related to method), context=None):

    return super(MODEL_NAME, self).ORM_METHOD_NAME(cr, uid, (List of required parameters related to method) context=context)

Avatar
Discard
Best Answer

The question title indicate that you 've known that there is something that is called 'super', so I think you should've done more search in the source code of the Odoo itself and see how this 'super' is used, then you can predict how it is used. I do this and this helps me formulate more specific questions. This would enhance you by the time.

Avatar
Discard