在 Odoo 10 中,当用户“A”创建新销售订单并将其分配给不同的销售人员(用户“B”)时,无论您对电子邮件模板/子类型/发送通知应用什么配置,都会自动发送电子邮件给客户和销售人员(我仍然对默认情况下向客户发送内部通知电子邮件所遵循的业务逻辑感到惊讶)。
电子邮件是众所周知的,格式如下:
"You have been assigned to SOxxxx."
更糟糕的是,电子邮件被设置为“自动删除”,因此您甚至不知道系统正在向客户发送什么(无评论)。
Odoo 10 CE 中的哪些模块、功能或设置应被覆盖以避免此类默认行为?
覆盖
_message_auto_subscribe_notify
类的 sale.order
方法并添加到上下文 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)
如果仅对通过自定义代码(例如开发的 API 端点)生成的 SaleOrder 禁用此功能,您可以在每个模型上使用
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-v16 的更新答案
from odoo import api, fields, models
#class MailThread(models.AbstractModel):
# _inherit = 'mail.thread'
# def _message_auto_subscribe_notify
class EventEvent(models.Model):
_inherit = 'event.event'
#_inherit = ['mail.thread'...]
# overr. to prevent automatical notifications subject='You have been assigned to XXX,
def _message_auto_subscribe_notify(self, partner_ids, template):
""" Notify new followers, using a template to render the content of the
notification message. Notifications pushed are done using the standard
notification mechanism in mail.thread. It is either inbox either email
depending on the partner state: no user (email, customer), share user
(email, customer) or Odoo user (notification_type defined in Settings>Users)
"""
# in mail.thread.py:
# if not self or self.env.context.get('mail_auto_subscribe_no_notify'):
# return
# ... subject=_('You have been assigned to %s', record.display_name),
return super(EventEvent, self.with_context(mail_auto_subscribe_no_notify=True))._message_auto_subscribe_notify(partner_ids, template)
#class SaleOrder(models.Model):
#_inherit = 'sale.order'
#_inherit = ['mail.thread'...]
# def _message_auto_subscribe_notify.....
#class AccountMove(models.Model):
#_inherit = 'account.move'
#_inherit = ['mail.thread'...]
# def _message_auto_subscribe_notify.....