Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
13 Odpowiedzi
34712 Widoki

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

Any one help me with simple example

Awatar
Odrzuć
Najlepsza odpowiedź


# 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

Awatar
Odrzuć
Najlepsza odpowiedź

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)
Awatar
Odrzuć
Autor

Thanks Dairidi

Najlepsza odpowiedź

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....

 

Awatar
Odrzuć

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.

Najlepsza odpowiedź


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)

Awatar
Odrzuć
Autor

Thank you Dep.

Najlepsza odpowiedź

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)

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
lut 25
2645
1
sie 24
2219
2
lis 24
3352
3
paź 23
14886
2
lut 23
2497