Reputation: 5495
In Odoo 10, when user "A" creates a new sales order and assigns it to a different salesperson (user "B"), no matter what configuration you have applied to email templates/subtypes/send notifications, an email is automatically sent to the customer and the salesperson (I am still amazed on which business logic was follow to send internal notification emails to customers by default).
The email is the well known one with this format:
"You have been assigned to SOxxxx."
To make things worse the email is set to "Auto-delete", so you do not even know what your system is sending to customers (no comments).
Which module or function or setting in Odoo 10 CE shall be overwritten to avoid such default behaviour?
Upvotes: 1
Views: 2203
Reputation: 1314
Here is an updated answer for Odoo-v16 (the function has a new argument: template)
from odoo import api, fields, models
#class MailThread(models.AbstractModel):
# _inherit = 'mail.thread'
# def _message_auto_subscribe_notify
class SaleOrder(models.Model):
_inherit = 'sale.order'
#_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),
self_ctx = self.with_context(mail_auto_subscribe_no_notify=True)
return super(SaleOrder,self_ctx)._message_auto_subscribe_notify(partner_ids,template)
#class EventEvent(models.Model):
# _inherit = 'event.event'
#_inherit = ['mail.thread'...]
# def _message_auto_subscribe_notify.....
Upvotes: 0
Reputation: 635
If this should only be disabled for SaleOrder which are generated through custom code (e.g. an developed API endpoint), you could use the with_context()
method on each model:
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)
In my example, the user with the ID 6 does not get the notification about the assignment of this sale order.
Upvotes: 0
Reputation: 780
Overwrite _message_auto_subscribe_notify
method for sale.order
class and add to context 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)
The original method will not send the message if that key is passed in the context
@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)
Upvotes: 4