Whenever I create a record like in subscription or change the states in the record, a mail is triggered to the followers present in record with the logs. How to stop sending these mails automatically which picks up the logs created in the form view?
Asked
Active
Viewed 1,477 times
2 Answers
1
Here is the create()
of mail.thread
where this comes from:
@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
As you can see there are some context flags to handle such situations. For your requirment mail_create_nolog
should be used:
@api.model
def create(self, vals):
return super(MyModel, self.with_context(mail_create_nolog=1)).create(vals)

CZoellner
- 13,553
- 3
- 25
- 38
-
So if I add this method sale subscription, then I won't be getting the mails? – Navi May 28 '19 at 11:44
-
1You can also use `mail_create_nosubscribe` to tell Odoo not to subscribe the creating user to the new thread (in your case a subscription). Or if you want to disable the whole thread features on creation just use `tracking_disable`. – CZoellner May 28 '19 at 11:46
0
Just go to settings->technical settings->subtype->disable the notification for your model.
In your case, for sale.subscription, Just disable the model by clicking the default checkbox.

Santhosh
- 209
- 2
- 16