Help

3

How do I 'call super' on ORM methods ?

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

Any one help me with simple example

Avatar
Discard
6 Answers
1
Avatar
Nimesh Jethva (nje)
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
4
Avatar
Dairidi
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)
1 Comment
Avatar
Discard
Avatar
Karthik Arumugam
-

Thanks Dairidi

2
Avatar
Baiju KS
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....

 

5 Comments
Avatar
Discard
Avatar
Tarek Mohamed Ibrahim
-

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

Avatar
Baiju KS
-

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.

Avatar
Tarek Mohamed Ibrahim
-

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.

Avatar
Baiju KS
-

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

Avatar
Tarek Mohamed Ibrahim
-

I got your idea, thx for clarification.

1
Avatar
Odoo
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)

1 Comment
Avatar
Discard
Avatar
Karthik Arumugam
-

Thank you Dep.

1
Avatar
Virali
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
-3
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