Browse Source

[10.0] partner_email_check: Multiple email check (#603)

pull/614/head
Abraham Anes 7 years ago
committed by Pedro M. Baeza
parent
commit
61e9a85bc6
  1. 10
      partner_email_check/models/res_partner.py
  2. 10
      partner_email_check/tests/test_partner_email_check.py

10
partner_email_check/models/res_partner.py

@ -29,8 +29,10 @@ class ResPartner(models.Model):
self.email_check(rec.email)
@api.model
def email_check(self, email):
if validate_email(email):
def email_check(self, emails):
for email in emails.split(','):
if not validate_email(email):
raise UserError(
_("%s is an invalid email") % email.strip()
)
return True
else:
raise UserError(_('Invalid e-mail!'))

10
partner_email_check/tests/test_partner_email_check.py

@ -22,3 +22,13 @@ class TestPartnerEmailCheck(TransactionCase):
"""Test acceptance of good"""
self.test_partner.email = 'goodemail@domain.com'
self.assertTrue(self.test_partner.email)
def test_bad_emails(self):
"""Test rejection of bad emails."""
with self.assertRaises(ValidationError):
self.test_partner.email = 'good@domain.com,bad@email@domain..com'
def test_good_emails(self):
"""Test acceptance of good"""
self.test_partner.email = 'goodemail@domain.com,goodemail2@domain.com'
self.assertTrue(self.test_partner.email)
Loading…
Cancel
Save