Navi
Navi

Reputation: 1052

How can I stop emails being sent automatically to followers when a record is created?

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?

Upvotes: 2

Views: 2302

Answers (2)

Santhosh
Santhosh

Reputation: 219

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.

Upvotes: 0

CZoellner
CZoellner

Reputation: 14778

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)

Upvotes: 1

Related Questions