Odoo Help

Welcome!

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

0

How to override BaseModel or Model class of orm.py?

By
sepdau
on 11/14/13, 6:23 AM 1,616 views

I wanna change something in export_data function then I wanna override BaseModel class. But really don't know how to override this? I try to copy a file file orm.py and fix import but the it not call in side this file.

0

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 11/14/13, 6:56 AM

First you have to inherit the class BaseModel and then can override the method.

Try this:

class Extend_BaseModel(BaseModel):
    def export_data(self, cr, uid, ids, fields_to_export, context=None):
        #Your code
        #You may call super also if you want like this: super(Extend_BaseModel, self).export_data(cr, uid, ids, fields_to_export, context=context)
        #Your code

Hope this will help you and solve you problem.

Thanks,

Serpent Consulting Services.

0
Mohamed Essakali
On 2/23/15, 6:40 PM

I achieve overriding BaseModel methods in V7 :

1- create a new python file my_basemodel.py

2- add your custom methods like this

from openerp.osv.orm import BaseModel

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

do_somthing

BaseModel.method = my_method    # Method is referring to an ORM methode (read, unlink, export_data, ...)

3- save the file and add it to __init__.py

4- Restart your server

0
Mohamed Mtloob
On 1/27/15, 5:19 AM

Dear Sir

it's not worked for me as seen this error

except_orm: ('ValueError', 'The class Extend_BaseModel has to have a _name attribute')

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 11/14/13, 6:23 AM
Seen: 1616 times
Last updated: 3/16/15, 8:10 AM