Ir al contenido
Menú
Se marcó esta pregunta
13 Respuestas
34285 Vistas

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

Any one help me with simple example

Avatar
Descartar
Mejor respuesta


# 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
Descartar
Mejor respuesta

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
Descartar
Autor

Thanks Dairidi

Mejor respuesta

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
Descartar

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.

Mejor respuesta


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
Descartar
Autor

Thank you Dep.

Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
4
feb 25
1744
1
ago 24
1724
2
nov 24
2735
3
oct 23
14438
2
feb 23
2170