Odoo Help

4

How to Override method of BaseModel/ ORM in odoo v8 ?

By
Anil R. Kesariya
on 9/3/14, 3:33 AM 3,190 views

In Base model method are defined using decorator.

I have tried to override the base model with this solution but it coudln't work.

    from openerp.models import BaseModel

    class custom_class(BaseModel)

        @api.multi

        def method_name

 

@ I have tried with applyting decorator and without decorator but my override function is not called yet. Any suggestion will be appreciated.

Why are you inheriting from BaseModel (i.e. class custom_class(BaseModel)). I did not found any use of BaseModel in this way in the addons, but maybe I'm missing something.

Lucio
on 9/3/14, 9:53 AM

I want to apply some global changes on odoo8 so for that I want to override the core methods or the main method. do you have any idea?

Anil R. Kesariya
on 9/3/14, 9:58 AM

Duplicate question maybe? https://www.odoo.com/forum/help-1/question/how-to-override-basemodel-or-model-class-of-orm-py-36517

Lucio
on 9/3/14, 11:17 AM
5

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11166
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

Top 10 Odoo contributor On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
On 9/3/14, 3:21 PM

Hello Anil,

Try can try with following example in which I have assigned my own method to read of base method:

from openerp.models import BaseModel

from openerp import api

@api.v8

def my_read(self, fields=None, load='_classic_read'):

#your code goes here

BaseModel.read = my_read

I guess this is what you are looking for.

Hope this will help you.

Thanks @Sudhir it works for me!

Anil R. Kesariya
on 9/4/14, 1:34 AM

And how do you actually override, let's say, the create function ? Because if you return BaaseModel.create at the end of your custom create, you will have recursion issues.

PY
on 7/1/15, 11:18 AM

You don't have to call no one. The return of the new method IS the return of the old method. The old one has been overwritten (i.e. replaced) altogether.

Lucio
on 7/16/15, 3:58 PM

hello Sudhir.. it gives me this error TypeError: my_user_has_groups() takes at least 4 arguments (2 given). Can you check this qtn ... http://stackoverflow.com/questions/34725611/how-to-override-method-of-basemodel-openerp-models-py-in-odoo-v9

manuthalasseril
on 1/11/16, 11:03 AM

About This Community

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

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

4 follower(s)

Stats

Asked: 9/3/14, 3:33 AM
Seen: 3190 times
Last updated: 12/5/17, 10:32 PM