From 61e9a85bc604c395fe79dc413641f7b08767d8fe Mon Sep 17 00:00:00 2001 From: Abraham Anes Date: Wed, 18 Jul 2018 00:31:22 +0200 Subject: [PATCH] [10.0] partner_email_check: Multiple email check (#603) --- partner_email_check/models/res_partner.py | 12 +++++++----- .../tests/test_partner_email_check.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/partner_email_check/models/res_partner.py b/partner_email_check/models/res_partner.py index afb3d47ae..ebcdbca11 100644 --- a/partner_email_check/models/res_partner.py +++ b/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): - return True - else: - raise UserError(_('Invalid e-mail!')) + 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 diff --git a/partner_email_check/tests/test_partner_email_check.py b/partner_email_check/tests/test_partner_email_check.py index 6050f3ad4..76a5952e7 100644 --- a/partner_email_check/tests/test_partner_email_check.py +++ b/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)