Odoo Help


How to redefine a method of a class osv.AbstracModel?

Carlos Almeida
on 1/19/16, 9:33 PM 994 views

I need to redefine mail_thread.message_post to change it's behaviour in version 8.0.

I've tried:

class MailThread(osv.AbstractModel):
""" Update MailThread to add the feature """
_inherit = 'mail.thread'
def message_post(self, cr, uid, thread_id, body='', subject=None,
type='notification', subtype=None, parent_id=False,
attachments=None, context=None, content_subtype='html',
         * * MY CODE * *
         thread_id = super(MailThread, self).message_post(self, cr, uid, thread_id,
                body=body, subject=subject, type=type, subtype=subtype,
parent_id=parent_id, attachments=attachments,
context=nosub_ctx, content_subtype=content_subtype, **kwargs)
         return thread_id

But my method is never called...

I've searched the code and found that others modules do that, could it be that theirs are not being executed also, or do they do something I'm missing? (ex: addons mass_mailing)

I've tried also with class name as mail_thread, no success.

I've looked to this code: 


But applying it makes mail_thread.message_post undefined.

Can one point me the right direction, thanks in advance!

Have you listed "mail" module as a dependency in a manifest file of your module (the 'depends' list in the __openerp__.py file)?

on 1/20/16, 5:57 AM

yes I did... :/ and not working

Carlos Almeida
on 1/26/16, 3:29 PM

Any further help on this?

Carlos Almeida
on 2/2/16, 7:37 AM
Kalpana Hemnani
On 1/21/16, 8:41 AM

Hello Carlos Almeida,

What you can do is, you can override this method in a model in which you want to customized code to execute.

You can refer calendar module for information. In calender.py you can find message_post() is overridden.

true but that will work only in calendar class, not on all classes that uses message_post(). the objective is to overide in all in one place. Otherwise we wil lhave to write a module for every existent module that uses message_post() :/

Carlos Almeida
on 1/26/16, 3:34 PM
On 1/20/16, 4:15 AM

Hello Carlos,

You can define new method in Your py point to old one like this

# Make Sure to Define this method outside of class

def  _your_new_method()

     your code

openerp.addons.mail.mail_thread.mail_thread.message_post = _your_new_method


This has quite some potential side effects and doesn't play well with other modules doing the same thing.

Carlos Almeida
on 1/20/16, 6:04 AM

In fact that makes the code to be executed even if the module is not installed on database. So it will run in all databases...

Carlos Almeida
on 1/20/16, 11:54 AM

It will be executed if that module is in your module list

on 1/20/16, 1:32 PM

any idea? is it even possible?

Carlos Almeida
on 1/26/16, 3:36 PM

It works as I defined new method as posted in answer

on 1/26/16, 3:46 PM

Another problem with Swapnesh proposal is that the code is always executed even if module not installed, and that caused a lot of problems :(

Carlos Almeida
on 2/2/16, 7:36 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.


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

1 follower(s)


Asked: 1/19/16, 9:33 PM
Seen: 994 times
Last updated: 1/21/16, 8:41 AM