Odoo Help

0

How to add functionality to the osv class?

By
Julian Solorzano
on 9/9/14, 2:36 PM 1,524 views

How to "directly" override a method in the osv Model class, such as write, create, etc, so that any new model that I create inherits this functionality?
I mean, suppose I am extending res.partner, sale.order, purchase.order and a bunch of other models, and I want to override write for all of them, adding the same code to every one (like logging or something). Can I do this without overriding write in every single model?

Already asked related questions 1) https://www.odoo.com/forum/help-1/question/how-to-override-method-of-basemodel-orm-in-odoo-v8-61799 2) https://www.odoo.com/forum/help-1/question/inherit-create-function-in-the-new-framework-62150#answer-62249

Anil R. Kesariya
on 9/10/14, 2:01 AM
1
Deviprasad V
On 9/10/14, 1:24 AM

Hi Julian,

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

     --- custome code --

after creating your method add this code

osv.osv.unlink = unlink
now your method is overrided the osv method
   

Thanks, this worked!

Zenpar S.A. de C.V., Julian Solorzano
on 9/11/14, 12:11 PM
1

Hi Julian,

You can do as you want. Just see the following ex for the write method. It is override the write method of the osv.

from openerp.osv import orm

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

 ..... Your code ...

    return True

orm.BaseModel.write = custom_write

 

Thanks this worked!

Zenpar S.A. de C.V., Julian Solorzano
on 9/11/14, 12:11 PM

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

2 follower(s)

Stats

Asked: 9/9/14, 2:36 PM
Seen: 1524 times
Last updated: 3/16/15, 8:10 AM