تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4616 أدوات العرض
I try to write to Chatter Box, but I have the below error:
ValueError: Posting a message should be done on a business document. Use message_notify to send a notification to an user.

My code:
@api.onchange("my_field")
def write_to_chatter(self):
​body = "My Message!"
   self.message_post(body=body, subtype='my_subtype')

Sources:

Add Message To Chatter From Code in Odoo

Cybrosys || How To Post A Message To Chatter In Odoo 16


الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Solved:

I used the write() method, I post a log note when the user saves their data.
def write(self, vals):
        if 'name' in vals:
            new_value = vals['name']
            old_value = self.name.id
            if new_value != old_value:
                message_body = _("%(user)s changed the Name to %(user_name)s",
                                 user=self.env.user.name,
                                 user_name=self.env['my.module'].search(domain=[('id', '=', new_value)]).name)
                self.message_post(body=message_body, message_type='notification')
        res = super().write(vals)
        return res
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 23
3605
4
يونيو 25
8810
2
أكتوبر 24
7709
2
سبتمبر 24
5179
2
مارس 24
3345