Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
6 Antwoorden
3729 Weergaven

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
Annuleer

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

Auteur

yes I did... :/ and not working

Auteur

Any further help on this?

Beste antwoord

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
Annuleer
Auteur

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

Beste antwoord

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
Annuleer
Auteur

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

Auteur

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

Auteur

any idea? is it even possible?

It works as I defined new method as posted in answer

Auteur

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