Search code examples
pythonodoo-11

Post a message on product form mail thread in odoo 11


I want to post a custom message on the product form mail thread programmatically, i've inhereted the product.template module and here's my code

from odoo import models,fields,api

class product_sheet(models.Model):

_inherit = ['product.template']

fieldx = fields.Float()

@api.onchange('fieldx')
def post_msg(self):
    self.message_post(body="Write something here")

I don't want to use the track_visibility, I just need to write something in the thread programmatically, but I don't know how the message_post method works

what's the correct way of doing this?


Solution

  • Your code should work. What is the error that you are getting? Could you post the traceback.

    Also you could try doing this in the write method, like this:

    @api.multi
    def write (self, values):
       res = super(YOURCLASS,self).write(values)
       if 'fieldx' in values:
           self.message_post(body="Write something")
       return res