Search code examples
odooodoo-8openerp-8

How to post a message in chatter during create method in Odoo?


I was writing create method for my own custom module.

def create(self, cr, uid,ids, context=None):
        self.message_post(cr, uid, ids, body=_("Form Page created"), context=None)

but i am getting the following error when saving AssertionError: Invalid thread_id; should be 0, False, an ID or a list with one ID

or sometimes

TypeError: create() got multiple values for keyword argument 'context'

i just want to post a message when it is created


Solution

  • Openerp 7 Create Method

    def create(self, cr, uid, vals, context=None):
         new_id = super(CRM_Lead, self).create(cr, uid, vals, context=context)
         return new_id
    

    odoo 8 Create Method:

    class ClassName(models.Model): _inherit = "model.name"

    @api.model
    def create(self, vals):
        rec = super(ClassName, self).create(vals)
        # ...        
        return rec
    

    Make sure you use the exact name of the python class in the super function and also that you return the same object you get from it.

    Track Visibility

    You can set a mail.message.subtype that depends on an other to act through a relation field.

    For better understanding track visibilty Refer This Link

    There is two type fileds of track visibility

    track_visibility='always' 
    track_visibility='onchange'