一、发送消息
1、发送消息
语法:
message_post(self, body='', subject=None, message_type='notification', subtype=None, parent_id=False, attachments=None, **kwargs)
在已存在的线程中发送一条信息,返回一个新的mail.message ID.
参数说明:
body (str) –消息内容,
message_type (str) – 消息类型
parent_id (int) – 父对象ID
attachments (list(tuple(str,str))) – 附件列表(名称,内容), 当内容不是code64位编码的时候。
**kwargs – 参数列表
subtype=None –子类
如subtype="mail.mt_comment":给mail.mt_comment这个模型的关注者发送消息
Returns: 新创建的mail.message记录的ID
Return type int:返回数据类型int
2、调用视图模板发送消息
语法:
message_post_with_view(views_or_xmlid, **kwargs)
调用VIEW视图模板作为辅助方法发送消息。
参数说明:
ir.ui.view record (str) – 模板ID
3、调用qweb模板发送消息
语法:
message_post_with_template(template_id, **kwargs)
调用QWEB模板作为辅助方法发送消息。
参数说明:
template_id – 模板ID
二、接受消息
当一条e-mail被邮件路由处理的时候,下面的 方法会被调用。
1、创建消息
message_new(msg_dict, custom_values=None)
根据相关的模型创建新的消息
参数说明:
msg_dict (dict) –消息内容和附件集合
custom_values (dict) – 自定义值
Return type int:返回数据类型int
Returns: 新创建的mail.message记录的ID
2、修改消息
message_update(msg_dict, update_vals=None)
参数说明:
msg_dict (dict) – 消息内容和附件集合.
update_vals (dict) – 要修改的值
Returns:True– 返回 true
三、“关注者”管理
1、
message_subscribe(partner_ids=None, channel_ids=None, subtype_ids=None, force=True)
添加伙伴到“关注者”
参数说明:
partner_ids (list(int)) – 伙伴IDS
channel_ids (list(int)) – 频道IDS
subtype_ids (list(int)) – 子类型IDS
force –如果设为 True, 在添加新的关注者前删除原有关注者
Returns:Success/Failure 返回成功/失败
Return type:bool返回类型:逻辑
2、
message_unsubscribe(partner_ids=None, channel_ids=None)
从记录的关注者中移动伙伴
参数说明:
partner_ids (list(int)) – 伙伴IDS
channel_ids (list(int)) – 频道IDS
Returns:True 返回真
Return type:bool返回类型:逻辑
3、
message_unsubscribe_users(user_ids=None)
Wrapper on message_subscribe, using users.
参数说明:
user_ids (list(int)) – 将取消订阅记录的用户的ID;如果没有,请取消订阅当前用户
Returns:True 返回真
Return type:bool返回类型:逻辑
四、日志记录管理
mail模块有字段修改跟踪功能,允许在特定字段上记录所有修改过程,如下:
例子:
class BusinessTrip(models.Model):
_name = 'business.trip'
_inherit = ['mail.thread']
_description = 'Business Trip'
name = fields.Char(tracking=True)
partner_id = fields.Many2one('res.partner', 'Responsible',
tracking=True)
guest_ids = fields.Many2many('res.partner', 'Participants')
中亿丰数字 姜振建