diff --git a/partner_ref_unique/README.rst b/partner_ref_unique/README.rst new file mode 100644 index 000000000..7a8502323 --- /dev/null +++ b/partner_ref_unique/README.rst @@ -0,0 +1,34 @@ +.. 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 unique reference +======================== + +Add an unique constraint to partner ref field + +Credits +======= + +Contributors +------------ + +* Antonio Espinosa + +Maintainer +---------- + +.. image:: http://www.antiun.com/images/logo-b.png + :alt: Antiun Ingeniería S.L. + :target: http://www.antiun.com + +This module is maintained by Antiun Ingeniería S.L. + +Antiun Ingeniería S.L. is an IT consulting company especialized in Odoo +and provides Odoo development, install, maintenance and hosting +services. + +To contribute to this module, please visit https://github.com/Antiun +or contact us at odoo@antiun.com + diff --git a/partner_ref_unique/__init__.py b/partner_ref_unique/__init__.py new file mode 100644 index 000000000..6b49297d7 --- /dev/null +++ b/partner_ref_unique/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/partner_ref_unique/__openerp__.py b/partner_ref_unique/__openerp__.py new file mode 100644 index 000000000..9a611b5eb --- /dev/null +++ b/partner_ref_unique/__openerp__.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner unique reference", + "summary": "Add an unique constraint to partner ref field", + "version": "8.0.1.0.0", + "category": "Customer Relationship Management", + "website": "http://www.antiun.com", + "author": "Antiun Ingeniería S.L.", + "license": "AGPL-3", + "application": False, + "installable": True, + # 'auto_install':False, + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "base", + ], + "data": [ + "views/res_company_view.xml", + ], + "demo": [ + ], + "qweb": [ + ] +} diff --git a/partner_ref_unique/models/__init__.py b/partner_ref_unique/models/__init__.py new file mode 100644 index 000000000..0b15881ca --- /dev/null +++ b/partner_ref_unique/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import res_company +from . import res_partner diff --git a/partner_ref_unique/models/res_company.py b/partner_ref_unique/models/res_company.py new file mode 100644 index 000000000..5b0909de9 --- /dev/null +++ b/partner_ref_unique/models/res_company.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields + + +class ResCompany(models.Model): + _inherit = "res.company" + + partner_ref_unique = fields.Selection( + selection=[ + ('none', 'None'), + ('companies', 'Only companies'), + ('all', 'All partners'), + ], string="Unique partner reference for", default="none") diff --git a/partner_ref_unique/models/res_partner.py b/partner_ref_unique/models/res_partner.py new file mode 100644 index 000000000..13b3284ef --- /dev/null +++ b/partner_ref_unique/models/res_partner.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api, _ +from openerp.exceptions import ValidationError + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.multi + @api.constrains('ref', 'is_company', 'company_id') + def _check_ref(self): + for partner in self: + mode = partner.company_id.partner_ref_unique + if (partner.ref and ( + mode == 'all' or + (mode == 'companies' and partner.is_company))): + domain = [ + ('id', '!=', partner.id), + ('ref', '=', partner.ref), + ('customer', '=', True), + ] + if mode == 'companies': + domain.append(('is_company', '=', True)) + other = self.search(domain) + if other: + raise ValidationError( + _("This reference is equal to partner '%s'") % + other[0].display_name) diff --git a/partner_ref_unique/static/description/icon.png b/partner_ref_unique/static/description/icon.png new file mode 100644 index 000000000..2d8a45c39 Binary files /dev/null and b/partner_ref_unique/static/description/icon.png differ diff --git a/partner_ref_unique/views/res_company_view.xml b/partner_ref_unique/views/res_company_view.xml new file mode 100644 index 000000000..261567487 --- /dev/null +++ b/partner_ref_unique/views/res_company_view.xml @@ -0,0 +1,23 @@ + + + + + + + Add partner_ref_unique field + res.company + + + + + + + + + + + + + +