Skip to Content
Menu
This question has been flagged
6 Replies
3206 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'
@api.cr_uid_ids_context
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',
**kwargs):
         * * 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: 

https://github.com/hbrunn/social/blob/8.0-mail_follower_custom_notification/mail_follower_custom_notification/models/mail_thread.py

But applying it makes mail_thread.message_post undefined.

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

Avatar
Discard

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

Author

yes I did... :/ and not working

Author

Any further help on this?

Best Answer

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.

Avatar
Discard
Author

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() :/

Best Answer

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




Thanks

Avatar
Discard
Author

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

Author

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

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

Author

any idea? is it even possible?

It works as I defined new method as posted in answer

Author

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