Openerp - 在创建产品时通过消息通知用户

时间:2014-06-05 10:59:35

标签: messaging openerp-7

我正在定制OpenERP。我需要在用户创建产品后立即向所有“采购经理”显示通知消息。

我看到在设置下创建了一条消息 - > 电子邮件 - >通过说“产品创建”消息。但是,主菜单消息传递 - >下的经理不会显示它的收件箱即可。

我希望将此消息作为管理员的通知。但是,无法在Google中找到任何好的文档。

如果我遗漏任何基本逻辑,请纠正我。

1 个答案:

答案 0 :(得分:2)

尝试继承产品模块并覆盖create方法,如下所示:

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