Browse Source

Add new module partner-email-check (#496)

* Add new module partner-email-check
Validate email input
14.0
denislour 7 years ago
committed by Zar21
parent
commit
56f992839f
  1. 56
      partner_email_check/README.rst
  2. 5
      partner_email_check/__init__.py
  3. 19
      partner_email_check/__manifest__.py
  4. 5
      partner_email_check/models/__init__.py
  5. 36
      partner_email_check/models/res_partner.py
  6. 5
      partner_email_check/tests/__init__.py
  7. 24
      partner_email_check/tests/test_partner_email_check.py

56
partner_email_check/README.rst

@ -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.

5
partner_email_check/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Komit <http://komit-consulting.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

19
partner_email_check/__manifest__.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Komit <http://komit-consulting.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Email Format Checker',
'version': '10.0.1.0.0',
'summary': 'Validate email address field',
'author': "Komit, Odoo Community Association (OCA)",
'website': 'http://komit-consulting.com',
'category': 'Tools',
'depends': ['base'],
'installable': True,
'application': False,
'license': 'AGPL-3',
'external_dependencies': {
'python': ['validate_email']
},
}

5
partner_email_check/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Komit <http://komit-consulting.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import res_partner

36
partner_email_check/models/res_partner.py

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Komit <http://komit-consulting.com>
# License AGPL-3.0 or later (http://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
else:
raise UserError(_('Invalid e-mail!'))

5
partner_email_check/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Komit <http://komit-consulting.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_partner_email_check

24
partner_email_check/tests/test_partner_email_check.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Komit <http://komit-consulting.com>
# License AGPL-3.0 or later (http://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)
Loading…
Cancel
Save