当用户在 Odoo 10 中创建销售订单时如何禁用 "You have been assigned" 电子邮件
How to disable "You have been assigned" email when a user creates a sales order in Odoo 10
在 Odoo 10 中,当用户“A”创建新的销售订单并将其分配给不同的销售人员(用户“B”)时,无论您对电子邮件 templates/subtypes/send 通知应用什么配置,一个电子邮件自动发送给客户和销售人员(我仍然很惊讶默认情况下遵循哪个业务逻辑向客户发送内部通知电子邮件)。
电子邮件是众所周知的格式:
"You have been assigned to SOxxxx."
更糟糕的是,电子邮件设置为“自动删除”,因此您甚至不知道您的系统向客户发送了什么(无评论)。
应覆盖 Odoo 10 CE 中的哪个模块或功能或设置以避免此类默认行为?
覆盖 sale.order
class 的 _message_auto_subscribe_notify
方法并添加到上下文 mail_auto_subscribe_no_notify.
from odoo import models, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def _message_auto_subscribe_notify(self, partner_ids):
""" Notify newly subscribed followers of the last posted message.
:param partner_ids : the list of partner to add as needaction partner of the last message
(This excludes the current partner)
"""
return super(SaleOrder, self.with_context(mail_auto_subscribe_no_notify=True))\
._message_auto_subscribe_notify(partner_ids)
如果在上下文中传递该键,原始方法将不会发送消息
@api.multi
def _message_auto_subscribe_notify(self, partner_ids):
""" Notify newly subscribed followers of the last posted message.
:param partner_ids : the list of partner to add as needaction partner of the last message
(This excludes the current partner)
"""
if not partner_ids:
return
if self.env.context.get('mail_auto_subscribe_no_notify'): # Here
return
# send the email only to the current record and not all the ids matching active_domain !
# by default, send_mail for mass_mail use the active_domain instead of active_ids.
if 'active_domain' in self.env.context:
ctx = dict(self.env.context)
ctx.pop('active_domain')
self = self.with_context(ctx)
for record in self:
record.message_post_with_view(
'mail.message_user_assigned',
composition_mode='mass_mail',
partner_ids=[(4, pid) for pid in partner_ids],
auto_delete=True,
auto_delete_message=True,
parent_id=False, # override accidental context defaults
subtype_id=self.env.ref('mail.mt_note').id)
如果只对通过自定义代码生成的 SaleOrder 禁用此功能(例如开发的 API 端点),您可以在每个模型上使用 with_context()
方法:
sale_order = {
'partner_id': partner['id'],
'state': 'sent',
'user_id': 6,
'source_id': 3,
'currency_id': currency['id'],
'payment_term_id': payment_term['id'],
}
created_sale_order = request.env['sale.order'].with_context(mail_auto_subscribe_no_notify=True).create(sale_order)
在我的示例中,ID 为 6 的用户不会收到有关分配此销售订单的通知。
在 Odoo 10 中,当用户“A”创建新的销售订单并将其分配给不同的销售人员(用户“B”)时,无论您对电子邮件 templates/subtypes/send 通知应用什么配置,一个电子邮件自动发送给客户和销售人员(我仍然很惊讶默认情况下遵循哪个业务逻辑向客户发送内部通知电子邮件)。
电子邮件是众所周知的格式:
"You have been assigned to SOxxxx."
更糟糕的是,电子邮件设置为“自动删除”,因此您甚至不知道您的系统向客户发送了什么(无评论)。
应覆盖 Odoo 10 CE 中的哪个模块或功能或设置以避免此类默认行为?
覆盖 sale.order
class 的 _message_auto_subscribe_notify
方法并添加到上下文 mail_auto_subscribe_no_notify.
from odoo import models, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def _message_auto_subscribe_notify(self, partner_ids):
""" Notify newly subscribed followers of the last posted message.
:param partner_ids : the list of partner to add as needaction partner of the last message
(This excludes the current partner)
"""
return super(SaleOrder, self.with_context(mail_auto_subscribe_no_notify=True))\
._message_auto_subscribe_notify(partner_ids)
如果在上下文中传递该键,原始方法将不会发送消息
@api.multi
def _message_auto_subscribe_notify(self, partner_ids):
""" Notify newly subscribed followers of the last posted message.
:param partner_ids : the list of partner to add as needaction partner of the last message
(This excludes the current partner)
"""
if not partner_ids:
return
if self.env.context.get('mail_auto_subscribe_no_notify'): # Here
return
# send the email only to the current record and not all the ids matching active_domain !
# by default, send_mail for mass_mail use the active_domain instead of active_ids.
if 'active_domain' in self.env.context:
ctx = dict(self.env.context)
ctx.pop('active_domain')
self = self.with_context(ctx)
for record in self:
record.message_post_with_view(
'mail.message_user_assigned',
composition_mode='mass_mail',
partner_ids=[(4, pid) for pid in partner_ids],
auto_delete=True,
auto_delete_message=True,
parent_id=False, # override accidental context defaults
subtype_id=self.env.ref('mail.mt_note').id)
如果只对通过自定义代码生成的 SaleOrder 禁用此功能(例如开发的 API 端点),您可以在每个模型上使用 with_context()
方法:
sale_order = {
'partner_id': partner['id'],
'state': 'sent',
'user_id': 6,
'source_id': 3,
'currency_id': currency['id'],
'payment_term_id': payment_term['id'],
}
created_sale_order = request.env['sale.order'].with_context(mail_auto_subscribe_no_notify=True).create(sale_order)
在我的示例中,ID 为 6 的用户不会收到有关分配此销售订单的通知。