Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
5854 Tampilan

Hey Guys 

Is there a way to avoid sending emails in Development / staging environment to customers/suppliers (a parameter to add, a context ....etc)?

NB: There is the solution to disable the outgoing servers, but I would like to keep it to test it for testing notifications, emails for users ...etc

I hope I was clear :) & thanks a lot

Avatar
Buang
Jawaban Terbai

Hi Othmane,

For which model/module/form, you want to avoid?

You need to set context flag to that model's message_post() and this method create mail record so context pass to mail creation method and in that method you can check condition that context flag found than block email sending otherwise send email.

I am giving you hint.

1) Basically email send when you send message from chatter (bottom of any form), so in that model of that form, there is a method called message_post() thhis method send mail. So here you can add context flag.

2) So where to check context flag?:
There is a method in mail module (mail/models/res_partner(line no: 88-191)), the method _notify(), will prepare mail data and send mail.

So in that method go to line no: 149 (email = Mail.create(create_values))

and add condition here to block email sending.

You can add code like

if not self._context.get('CONTEXT_FLAG'):
# Line no: 149-164
email = Mail.create(create_values)

if email and recipient_ids:
    notifications = self.env['mail.notification'].sudo().search([
        ('mail_message_id', '=', email.mail_message_id.id),
        ('res_partner_id', 'in', list(recipient_ids))
    ])
    notifications.write({
        'is_email': True,
        'mail_id': email.id,
        'is_read': True,  # handle by email discards Inbox notification
        'email_status': 'ready',
    })

emails |= email
email_pids.update(recipient_ids)

I know it's innocent thing, but if you want to block for specific purpose then you need to custome code like this.

I hope it will helpful for you.

Thanks and regards
Haresh Kansara

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
3
Agu 19
8774
0
Apr 18
2781
0
Mei 24
2076
0
Feb 24
1625
2
Mar 23
3921