每当我创建诸如订阅中的记录或更改记录中的状态时,就会向记录中包含日志的关注者触发一封邮件。如何停止自动发送这些邮件,以获取在表单视图中创建的日志?
答案 0 :(得分:1)
这是create()
中的mail.thread
,它来自:
@api.model
def create(self, values):
""" Chatter override :
- subscribe uid
- subscribe followers of parent
- log a creation message
"""
if self._context.get('tracking_disable'):
return super(MailThread, self).create(values)
# subscribe uid unless asked not to
if not self._context.get('mail_create_nosubscribe'):
message_follower_ids = values.get('message_follower_ids') or [] # webclient can send None or False
message_follower_ids += self.env['mail.followers']._add_follower_command(self._name, [], {self.env.user.partner_id.id: None}, {}, force=True)[0]
values['message_follower_ids'] = message_follower_ids
thread = super(MailThread, self).create(values)
# automatic logging unless asked not to (mainly for various testing purpose)
if not self._context.get('mail_create_nolog'):
doc_name = self.env['ir.model'].search([('model', '=', self._name)]).read(['name'])[0]['name']
thread.message_post(body=_('%s created') % doc_name)
# auto_subscribe: take values and defaults into account
create_values = dict(values)
for key, val in self._context.iteritems():
if key.startswith('default_') and key[8:] not in create_values:
create_values[key[8:]] = val
thread.message_auto_subscribe(create_values.keys(), values=create_values)
# track values
if not self._context.get('mail_notrack'):
if 'lang' not in self._context:
track_thread = thread.with_context(lang=self.env.user.lang)
else:
track_thread = thread
tracked_fields = track_thread._get_tracked_fields(values.keys())
if tracked_fields:
initial_values = {thread.id: dict.fromkeys(tracked_fields, False)}
track_thread.message_track(tracked_fields, initial_values)
return thread
如您所见,有一些上下文标志可以处理这种情况。对于您的要求,应使用mail_create_nolog
:
@api.model
def create(self, vals):
return super(MyModel, self.with_context(mail_create_nolog=1)).create(vals)
答案 1 :(得分:1)
只需转到设置->技术设置->子类型->为您的模型禁用通知。
对于您的情况,对于sale.subscription,只需单击默认复选框即可禁用模型。