gpt4 book ai didi

odoo - 创建记录时,如何停止向关注者自动发送电子邮件?

转载 作者:行者123 更新时间:2023-12-05 01:31:40 27 4
gpt4 key购买 nike

每当我在订阅中创建记录或更改记录中的状态时,都会向记录中的关注者触发一封邮件。如何停止自动发送这些邮件以获取在表单 View 中创建的日志?

最佳答案

这里是 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)

关于odoo - 创建记录时,如何停止向关注者自动发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56339405/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com