diff --git a/partner_email_unique/README.rst b/partner_email_unique/README.rst new file mode 100644 index 000000000..ae2947018 --- /dev/null +++ b/partner_email_unique/README.rst @@ -0,0 +1,80 @@ +==================== +Partner unique email +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/9.0/partner_email_unique + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-9-0/partner-contact-9-0-partner_email_unique + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/134/9.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add an unique constraint to partner email field + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +* Try to create two partners with the same email. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Coop IT Easy SCRL fs + +Contributors +~~~~~~~~~~~~ + +* Robin Keunen + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_email_unique/__init__.py b/partner_email_unique/__init__.py new file mode 100644 index 000000000..21e6c1fea --- /dev/null +++ b/partner_email_unique/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/partner_email_unique/__openerp__.py b/partner_email_unique/__openerp__.py new file mode 100644 index 000000000..299bfb638 --- /dev/null +++ b/partner_email_unique/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner unique email", + "summary": "Add an unique constraint to email field", + "version": "9.0.1.0.0", + "category": "Customer Relationship Management", + "website": "https://github.com/oca/partner-contact", + "author": "Coop IT Easy SCRL fs, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "base", + ], +} diff --git a/partner_email_unique/models/__init__.py b/partner_email_unique/models/__init__.py new file mode 100644 index 000000000..8965be594 --- /dev/null +++ b/partner_email_unique/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import res_partner diff --git a/partner_email_unique/models/res_partner.py b/partner_email_unique/models/res_partner.py new file mode 100644 index 000000000..7fde1488e --- /dev/null +++ b/partner_email_unique/models/res_partner.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import models, api, _ +from openerp.exceptions import ValidationError +from openerp.tools import config + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.multi + @api.constrains('email') + def _check_email(self): + if config['test_enable'] and not self.env.context.get( + 'test_partner_email_unique'): + return + + for partner in self: + domain = [ + ('id', '!=', partner.id), + ('email', '=', partner.email), + ] + other_partners = self.search(domain) + + # active_test is False when called from + # base.partner.merge.automatic.wizard + if other_partners and self.env.context.get("active_test", True): + raise ValidationError( + _("This email is already set to partner '%s'") + % other_partners[0].display_name) diff --git a/partner_email_unique/readme/CONTRIBUTORS.rst b/partner_email_unique/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..0ecb06105 --- /dev/null +++ b/partner_email_unique/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Robin Keunen diff --git a/partner_email_unique/readme/DESCRIPTION.rst b/partner_email_unique/readme/DESCRIPTION.rst new file mode 100644 index 000000000..703b3c996 --- /dev/null +++ b/partner_email_unique/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Add an unique constraint to partner email field diff --git a/partner_email_unique/readme/USAGE.rst b/partner_email_unique/readme/USAGE.rst new file mode 100644 index 000000000..73f852924 --- /dev/null +++ b/partner_email_unique/readme/USAGE.rst @@ -0,0 +1,3 @@ +To use this module, you need to: + +* Try to create two partners with the same email. diff --git a/partner_email_unique/static/description/index.html b/partner_email_unique/static/description/index.html new file mode 100644 index 000000000..a93e0181e --- /dev/null +++ b/partner_email_unique/static/description/index.html @@ -0,0 +1,427 @@ + + + + + + +Partner unique email + + + +
+

Partner unique email

+ + +

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

+

Add an unique constraint to partner email field

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  • Try to create two partners with the same email.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Coop IT Easy SCRL fs
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/partner-contact project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/partner_email_unique/tests/__init__.py b/partner_email_unique/tests/__init__.py new file mode 100644 index 000000000..1ee35ecb8 --- /dev/null +++ b/partner_email_unique/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_res_partner_email diff --git a/partner_email_unique/tests/test_res_partner_email.py b/partner_email_unique/tests/test_res_partner_email.py new file mode 100644 index 000000000..20ca7bdb2 --- /dev/null +++ b/partner_email_unique/tests/test_res_partner_email.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common +from openerp.exceptions import ValidationError + + +class TestResPartnerEmailUnique(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestResPartnerEmailUnique, cls).setUpClass() + partner_obj = ( + cls.env['res.partner'] + .with_context({'test_partner_email_unique': True}) + ) + cls.partner1 = partner_obj.create({ + 'name': 'Partner1', + }) + cls.partner2 = partner_obj.create({ + 'name': 'Partner2', + }) + + def test_check_email(self): + + # Test can create/modify partners with different email + self.partner1.email = 'same_email@test.com' + self.partner2.email = 'different_email@test.com' + self.assertNotEqual(self.partner1.email, self.partner2.email) + self.partner2.ref = False + + # Test can't create/modify partner with same email + with self.assertRaises(ValidationError): + self.partner2.email = 'same_email@test.com'