Browse Source
Merge pull request #543 from denislour/11.0-mig-partner_email_check
11.0 mig partner email check
pull/586/merge
Ronald Portier
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
141 additions and
0 deletions
-
partner_email_check/README.rst
-
partner_email_check/__init__.py
-
partner_email_check/__manifest__.py
-
partner_email_check/models/__init__.py
-
partner_email_check/models/res_partner.py
-
partner_email_check/tests/__init__.py
-
partner_email_check/tests/test_partner_email_check.py
-
requirements.txt
|
|
@ -0,0 +1,56 @@ |
|
|
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|
|
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
|
|
|
:alt: License: AGPL-3 |
|
|
|
|
|
|
|
=================== |
|
|
|
Partner Email Check |
|
|
|
=================== |
|
|
|
|
|
|
|
This module validate the field ``email`` in the module ``res.partner``. |
|
|
|
|
|
|
|
Configuration |
|
|
|
============= |
|
|
|
|
|
|
|
Install python package validate_email: ``sudo pip install validate_email``. |
|
|
|
|
|
|
|
Usage |
|
|
|
===== |
|
|
|
|
|
|
|
This module integrate automatically in all of the view ``res.partner`` |
|
|
|
|
|
|
|
Bug Tracker |
|
|
|
=========== |
|
|
|
|
|
|
|
Bugs are tracked on `GitHub Issues |
|
|
|
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please |
|
|
|
check there if your issue has already been reported. If you spotted it first, |
|
|
|
help us smashing it by providing a detailed and welcomed feedback. |
|
|
|
|
|
|
|
Credits |
|
|
|
======= |
|
|
|
|
|
|
|
Images |
|
|
|
------ |
|
|
|
|
|
|
|
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
|
|
|
|
|
|
|
Contributors |
|
|
|
------------ |
|
|
|
|
|
|
|
* Vo Hoang Dat <dat.vh@komit-consulting.com> |
|
|
|
* Jean-Charles Drubay <jc@komit-consulting.com> |
|
|
|
|
|
|
|
Maintainer |
|
|
|
---------- |
|
|
|
|
|
|
|
.. image:: https://odoo-community.org/logo.png |
|
|
|
:alt: Odoo Community Association |
|
|
|
:target: https://odoo-community.org |
|
|
|
|
|
|
|
This module is maintained by the OCA. |
|
|
|
|
|
|
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
|
|
|
mission is to support the collaborative development of Odoo features and |
|
|
|
promote its widespread use. |
|
|
|
|
|
|
|
To contribute to this module, please visit https://odoo-community.org. |
|
|
@ -0,0 +1,3 @@ |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
from . import models |
|
|
@ -0,0 +1,18 @@ |
|
|
|
# Copyright 2019 Komit <https://komit-consulting.com> |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
{ |
|
|
|
'name': 'Email Format Checker', |
|
|
|
'version': '11.0.1.0.0', |
|
|
|
'summary': 'Validate email address field', |
|
|
|
'author': "Komit, Odoo Community Association (OCA)", |
|
|
|
'website': 'https://github.com/OCA/partner-contact', |
|
|
|
'category': 'Tools', |
|
|
|
'depends': ['base'], |
|
|
|
'installable': True, |
|
|
|
'application': False, |
|
|
|
'license': 'AGPL-3', |
|
|
|
'external_dependencies': { |
|
|
|
'python': ['validate_email'] |
|
|
|
}, |
|
|
|
} |
|
|
@ -0,0 +1,3 @@ |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
from . import res_partner |
|
|
@ -0,0 +1,34 @@ |
|
|
|
# Copyright 2019 Komit <https://komit-consulting.com> |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
import logging |
|
|
|
from odoo import api, models, _ |
|
|
|
from odoo.exceptions import UserError |
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
try: |
|
|
|
from validate_email import validate_email |
|
|
|
except ImportError: |
|
|
|
_logger.error('Cannot import "validate_email".') |
|
|
|
|
|
|
|
def validate_email(email): |
|
|
|
_logger.warning( |
|
|
|
'Can not validate email, ' |
|
|
|
'python dependency required "validate_email"') |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model): |
|
|
|
_inherit = 'res.partner' |
|
|
|
|
|
|
|
@api.constrains('email') |
|
|
|
def constrains_email(self): |
|
|
|
for rec in self.filtered("email"): |
|
|
|
self.email_check(rec.email) |
|
|
|
|
|
|
|
@api.model |
|
|
|
def email_check(self, email): |
|
|
|
if validate_email(email): |
|
|
|
return True |
|
|
|
raise UserError(_('Invalid e-mail!')) |
|
|
@ -0,0 +1,3 @@ |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
from . import test_partner_email_check |
|
|
@ -0,0 +1,23 @@ |
|
|
|
# Copyright 2019 Komit <https://komit-consulting.com> |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
from odoo.exceptions import ValidationError |
|
|
|
from odoo.tests.common import TransactionCase |
|
|
|
|
|
|
|
|
|
|
|
class TestPartnerEmailCheck(TransactionCase): |
|
|
|
def setUp(self): |
|
|
|
super(TestPartnerEmailCheck, self).setUp() |
|
|
|
self.test_partner = self.env['res.partner'].create({ |
|
|
|
'name': 'test', |
|
|
|
}) |
|
|
|
|
|
|
|
def test_bad_email(self): |
|
|
|
"""Test rejection of bad emails.""" |
|
|
|
with self.assertRaises(ValidationError): |
|
|
|
self.test_partner.email = 'bad@email@domain..com' |
|
|
|
|
|
|
|
def test_good_email(self): |
|
|
|
"""Test acceptance of good""" |
|
|
|
self.test_partner.email = 'goodemail@domain.com' |
|
|
|
self.assertTrue(self.test_partner.email) |
|
|
@ -0,0 +1 @@ |
|
|
|
validate_email |