[IMP] mass_mailing : add invalid mass mailing contact email filter
In order to be aligned with the valid recipients counter on mass mailing list, the valid recipients filter should also exclude invalid emails.
This commit is contained in:
@@ -5,6 +5,7 @@ import hashlib
|
||||
import hmac
|
||||
import logging
|
||||
import random
|
||||
import re
|
||||
import threading
|
||||
from ast import literal_eval
|
||||
|
||||
@@ -23,6 +24,7 @@ MASS_MAILING_BUSINESS_MODELS = [
|
||||
'sale.order',
|
||||
'mail.mass_mailing.list',
|
||||
]
|
||||
EMAIL_PATTERN = '([^ ,;<@]+@[^> ,;]+)'
|
||||
|
||||
|
||||
class MassMailingTag(models.Model):
|
||||
@@ -115,10 +117,10 @@ class MassMailingList(models.Model):
|
||||
where
|
||||
COALESCE(r.opt_out,FALSE) = FALSE
|
||||
AND c.email NOT IN (select email from mail_blacklist where active = TRUE)
|
||||
AND substring(c.email, '([^ ,;<@]+@[^> ,;]+)') IS NOT NULL
|
||||
AND substring(c.email, '%s') IS NOT NULL
|
||||
group by
|
||||
list_id
|
||||
''')
|
||||
''' % EMAIL_PATTERN)
|
||||
data = dict(self.env.cr.fetchall())
|
||||
for mailing_list in self:
|
||||
mailing_list.contact_nbr = data.get(mailing_list.id, 0)
|
||||
@@ -210,6 +212,7 @@ class MassMailingContact(models.Model):
|
||||
company_name = fields.Char(string='Company Name')
|
||||
title_id = fields.Many2one('res.partner.title', string='Title')
|
||||
email = fields.Char(required=True)
|
||||
is_email_valid = fields.Boolean(compute='_compute_is_email_valid', store=True)
|
||||
create_date = fields.Datetime(string='Creation Date')
|
||||
list_ids = fields.Many2many(
|
||||
'mail.mass_mailing.list', 'mail_mass_mailing_contact_list_rel',
|
||||
@@ -220,6 +223,11 @@ class MassMailingContact(models.Model):
|
||||
country_id = fields.Many2one('res.country', string='Country')
|
||||
tag_ids = fields.Many2many('res.partner.category', string='Tags')
|
||||
|
||||
@api.depends('email')
|
||||
def _compute_is_email_valid(self):
|
||||
for record in self:
|
||||
record.is_email_valid = re.match(EMAIL_PATTERN, record.email)
|
||||
|
||||
def get_name_email(self, name):
|
||||
name, email = self.env['res.partner']._parse_partner_name(name)
|
||||
if name and not email:
|
||||
|
||||
@@ -61,11 +61,13 @@
|
||||
<field name="opt_out"/>
|
||||
<field name="list_id"/>
|
||||
<separator/>
|
||||
<filter string="Valid Recipients" name="valid_recipients" domain="[('opt_out', '=', False), ('contact_id.is_blacklisted', '=', False), ('contact_id.is_email_valid', '=', True)]"/>
|
||||
<separator/>
|
||||
<filter string="Exclude Opt Out" name="not_opt_out" domain="[('opt_out', '=', False)]"/>
|
||||
<separator/>
|
||||
<filter string="Exclude Blacklisted" name="not_blacklisted" domain="[('contact_id.is_blacklisted', '=', False)]"/>
|
||||
<separator/>
|
||||
<filter string="Valid Recipents" name="valid_recipients" domain="[('opt_out', '=', False), ('contact_id.is_blacklisted', '=', False)]"/>
|
||||
<filter string="Exclude Invalid Emails" name="valid_email" domain="[('contact_id.is_email_valid', '=', True)]"/>
|
||||
<separator/>
|
||||
<filter string="Exclude Bounced" name="not_bounced" domain="[('message_bounce', '<', 3)]"/>
|
||||
<group expand="0" string="Group By">
|
||||
|
||||
Reference in New Issue
Block a user