Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] partner_email_unique #293

Open
wants to merge 8 commits into
base: 12.0
Choose a base branch
from
80 changes: 80 additions & 0 deletions partner_email_unique/README.rst
Original file line number Diff line number Diff line change
@@ -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 <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 <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_email_unique%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Coop IT Easy SC

Contributors
~~~~~~~~~~~~

* Robin Keunen <[email protected]>

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 <https://github.com/OCA/partner-contact/tree/9.0/partner_email_unique>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions partner_email_unique/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2019 Coop IT Easy SC
# Robin Keunen <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
18 changes: 18 additions & 0 deletions partner_email_unique/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2019 Coop IT Easy SC
# Robin Keunen <[email protected]>
# 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": "12.0.1.0.0",
"category": "Customer Relationship Management",
"website": "https://github.com/oca/partner-contact",
"author": "Coop IT Easy SC, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"base",
],
}
26 changes: 26 additions & 0 deletions partner_email_unique/i18n/partner_email_unique.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_email_unique
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: partner_email_unique
#: model:ir.model,name:partner_email_unique.model_res_partner
msgid "Partner"
msgstr ""

#. module: partner_email_unique
#: code:addons/partner_email_unique/models/res_partner.py:35
#, python-format
msgid "This email is already set to partner '%s'"
msgstr ""

5 changes: 5 additions & 0 deletions partner_email_unique/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2019 Coop IT Easy SC
# Robin Keunen <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import res_partner
39 changes: 39 additions & 0 deletions partner_email_unique/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2019 Coop IT Easy SC
# Robin Keunen <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import os

from odoo import models, api, _, fields
from odoo.exceptions import ValidationError
from odoo.tools import config


class ResPartner(models.Model):
_inherit = "res.partner"

email = fields.Char(copy=False)

@api.multi
@api.constrains("email")
def _check_email(self):
if (
config["test_enable"] or os.environ.get("TESTS")
) and not self.env.context.get("test_partner_email_unique"):
return

for partner in self:
domain = [
("id", "!=", partner.id),
("email", "=", partner.email),
("email", "!=", False),
]
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
)
1 change: 1 addition & 0 deletions partner_email_unique/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Robin Keunen <[email protected]>
1 change: 1 addition & 0 deletions partner_email_unique/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add an unique constraint to partner email field
3 changes: 3 additions & 0 deletions partner_email_unique/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To use this module, you need to:

* Try to create two partners with the same email.
Binary file added partner_email_unique/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading