我正在定制OpenERP。我需要在用户创建产品后立即向所有“采购经理”显示通知消息。
我看到在设置 -> 电子邮件 -> 消息下创建了一条消息,内容为“产品已创建”。但是,它不会在主菜单消息传递 -> 收件箱下向经理显示。
我想将此消息作为经理的通知。但是,在 Google 中找不到任何好的文档。
如果我遗漏了任何基本逻辑,请纠正我。
最佳答案
尝试继承产品模块并重写 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
关于messaging - Openerp - 创建产品时通过消息通知用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24058426/