我想给制造组的每个人发一份通知,所以我试过这个代码,但它不起作用
manf_categ_ids=self.pool.get('ir.module.category').search(cr,uid,[('name','=','Manufacturing')],context=context)[0]
users=self.pool.get('res.groups').browse(cr, uid, manf_categ_ids , context=context).users
for user in users:
recipient_partners = []
recipient_partners.append(
(4, user.partner_id.id)
)
#user_ids=self.pool.get('res.users').search(cr,uid,[('groups_id','=',manf_categ_ids)],context=context)
post_vars = {'subject': "notification about order",
'body': "Yes inform me as i belong to manfacture group",
'partner_ids': recipient_partners,} # Where "4" adds the ID to the list
# of followers and "3" is the partner ID
thread_pool = self.pool.get('mail.thread')
thread_pool.message_post(
cr, uid, False,
type="notification",
subtype="mt_comment",
context=context,
**post_vars)
2个用户属于制造组,但用户列表仅包含1个元素,当我使用此用户登录时,此代码不发送任何通知
问题似乎是每次迭代都要清除列表。
线路
应该在
for
循环之外。首先,您需要使用合作伙伴的id,而不是用户的id。其次,您需要添加所有用户,而不仅仅是第一个用户。
这是一段基于我在项目中创建数组的代码,该数组可以用作
partner_ids
参数的值:你可以看到the code this is based on here。它从MessageTemplate的
send_group
方法开始,然后继续到send
方法。您目前似乎没有使用新的Odoo ORM API。你可以开始使用它(我强烈推荐!)或者将旧API所需的参数(cr、uid、context)添加到
search()
方法中,并使用browse()
获取完整的用户对象。相关问题 更多 >
编程相关推荐