Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
28508 Переглядів

Technically speaking I want to use the method responsible of posting messages on the discussion thread, existing below every form on openerp. 

How can I do this simple message post. Like when the object changes his status, the change is recorded on the discussion thread, to keep trace.

I searched on the mail module, especially on the mail_thread.py, I found the method : message_post, is this the methos I'm looking for ? Hope someone did it before me, so he can show me quickly how it can be done properly.

Thanks.

Аватар
Відмінити
Найкраща відповідь

Here the code below can guide you;

from odoo import fields, models, ....

class Anything(models.Model):

    _name = 'model.name'
    _inherit = ['mail.thread', 'ir.needaction_mixin']

    @api.model
    def create(self, vals):
        res = super(Anything, self).create(vals)
        if vals:
            self.message_post(body=body, res)
        return res


   ####### FOR BUTTON CLICK USE

    @api.multi
    def button_send_message(self):
            for rec in self:

            body ="Message has been approved on %s", %datetime.datetime.now()
            rec.message_post(body=body)


Аватар
Відмінити
Найкраща відповідь

Hi, please find below an example of posting the message as you requested:

self.message_post(cr, uid, this.id, body=("My custom message with dynamic text: %s") % (my_dynamic_text), context=context)

where 'this' is the browse object of the current record you want to post the message for.

This works if your class inherits the messaging behaviour, as you suggested in your question.
I hope this helps!

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
січ. 23
11869
1
лист. 17
5989
1
трав. 25
480
2
трав. 25
267
0
квіт. 25
535