Search code examples
messagingopenerp-7

Openerp - notify users by message when a product has been created


I am customizing OpenERP. I need to display a notification message to all "Purchase Managers" as soon as a product created by user.

I saw a message is created under settings -> Email -> Messages by saying "Product Created". However it is not displaying for the managers under main menu Messaging -> Inbox.

I want put this message as notification for managers. However, not able to find any good documentation in Google.

Correct me if I am missing any basic logic.


Solution

  • Try to inherit the product module and override the create method like this:

    def create(self, cr, uid, datas, context=None):
        new_id = super(class_name, self).create(cr, uid, datas, context=context)
        self.log_prod(cr, uid, new_id, context)
        return new_id
    
    def log_prod(self, cr, uid, ids, context=None):
        product = self.pool.get('product.product').browse(cr, uid, ids)
        msg = "Product %s has been created" % product.name
        msg_id = self.message_post(cr, uid, ids, body=msg, context=context)
        notif_obj = self.pool.get('mail.notification')
        all_groups = self.pool.get('res.groups')
        h1m_group = all_groups.browse(
                cr,
                uid,
                all_groups.search(
                        cr,
                        uid,
                        [('name','=','Access Rights')],
                ))
        for ids in h1m_group[0].users:
            notif_obj.create(
                    cr,
                    uid,
                    {
                        'partner_id': ids.partner_id.id,
                        'read': False,
                        'message_id': msg_id,
                    },
                    context=context)
        return True