在我的OpenERP模块中,我有时需要向用户发送通知或消息,但是(至少对我来说)使用res.users.message_post
消息的明显方式(至少对我而言)是将消息记录在用户记录上,而不是将消息发送给用户。有任何想法吗?
在发送消息之前,您需要先Social Network
安装模块(.../addons/mail
如果您想查看其代码,则该模块位于其中)。
之后,以下代码段将完成此工作:
from openerp import SUPERUSER_ID
def send_message(oe, cr, user_ids, subject, body):
"sends message to user_ids"
mail_message = oe.pool.get('mail.message')
mail_message_subtype = oe.pool.get('mail.message.subtype')
[discussion_id] = mail_message_subtype.browse(
cr, SUPERUSER_ID, [('name','=','Discussions')]
)
users = oe.pool.get('res.users').search(cr, uid, user_ids)
mail_message.create(cr, SUPERUSER_ID, values=dict(
type='email',
subtype_id=discussion.id,
partner_ids=[(4, u.partner_id.id) for u in users],
subject=subject,
body=body,
))
将其塞入某个实用程序模块中的某个位置,就可以了。
几个评论:
self
作为第一个参数传递send_message(self, cr, ...)
oe
的用self
,而忽略self
从参数本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句