Browse Source
Merge pull request #370 from Tecnativa/9.0-mig-partner_ref_unique
Merge pull request #370 from Tecnativa/9.0-mig-partner_ref_unique
[9.0][ADD] partner_ref_unique modulepull/368/head
Pedro M. Baeza
8 years ago
committed by
GitHub
10 changed files with 214 additions and 0 deletions
-
59partner_ref_unique/README.rst
-
5partner_ref_unique/__init__.py
-
24partner_ref_unique/__openerp__.py
-
6partner_ref_unique/models/__init__.py
-
16partner_ref_unique/models/res_company.py
-
34partner_ref_unique/models/res_partner.py
-
BINpartner_ref_unique/static/description/icon.png
-
5partner_ref_unique/tests/__init__.py
-
43partner_ref_unique/tests/test_res_partner_ref.py
-
22partner_ref_unique/views/res_company_view.xml
@ -0,0 +1,59 @@ |
|||
.. 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 |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
To use this module, you need to: |
|||
|
|||
* Go to your company settings and choose an option on section *Partner* in tab |
|||
*Configuration*. |
|||
* Try to create two partners with the same ref. |
|||
|
|||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
|||
:alt: Try me on Runbot |
|||
:target: https://runbot.odoo-community.org/runbot/134/9.0 |
|||
|
|||
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 |
|||
------------ |
|||
|
|||
* Antonio Espinosa <antonioea@antiun.com> |
|||
* Vicent Cubells <vicent.cubells@tecnativa.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,5 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import models |
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa |
|||
# Copyright 2017 Tecnativa - Vicent Cubells |
|||
# 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": "9.0.1.0.0", |
|||
"category": "Customer Relationship Management", |
|||
"website": "http://www.antiun.com", |
|||
"author": "Antiun Ingeniería S.L., " |
|||
"Tecnativa, " |
|||
"Odoo Community Association (OCA)", |
|||
"license": "AGPL-3", |
|||
"application": False, |
|||
"installable": True, |
|||
"depends": [ |
|||
"base", |
|||
], |
|||
"data": [ |
|||
"views/res_company_view.xml", |
|||
], |
|||
} |
@ -0,0 +1,6 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 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 |
@ -0,0 +1,16 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 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") |
@ -0,0 +1,34 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 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) |
|||
|
|||
# active_test is False when called from |
|||
# base.partner.merge.automatic.wizard |
|||
if other and self.env.context.get("active_test", True): |
|||
raise ValidationError( |
|||
_("This reference is equal to partner '%s'") % |
|||
other[0].display_name) |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,5 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 Tecnativa - Vicent Cubells |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import test_res_partner_ref |
@ -0,0 +1,43 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 Tecnativa - Vicent Cubells |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from openerp.tests import common |
|||
from openerp.exceptions import ValidationError |
|||
|
|||
|
|||
class TestResPartnerRefUnique(common.SavepointCase): |
|||
@classmethod |
|||
def setUpClass(cls): |
|||
super(TestResPartnerRefUnique, cls).setUpClass() |
|||
cls.company = cls.env.ref('base.main_company') |
|||
partner_obj = cls.env['res.partner'] |
|||
cls.partner1 = partner_obj.create({ |
|||
'name': 'Partner1', |
|||
}) |
|||
cls.partner2 = partner_obj.create({ |
|||
'name': 'Partner2', |
|||
}) |
|||
|
|||
def test_check_ref(self): |
|||
# Test can create/modify partners with same ref |
|||
self.company.partner_ref_unique = 'none' |
|||
self.partner1.ref = 'same_ref' |
|||
self.partner2.ref = 'same_ref' |
|||
self.assertEqual(self.partner1.ref, self.partner2.ref) |
|||
self.partner2.ref = False |
|||
|
|||
# Test can't create/modify partner with same ref |
|||
self.company.partner_ref_unique = 'all' |
|||
with self.assertRaises(ValidationError): |
|||
self.partner2.ref = 'same_ref' |
|||
|
|||
# Test can't create/modify companies with same ref |
|||
self.company.partner_ref_unique = 'companies' |
|||
self.partner2.ref = 'same_ref' |
|||
self.assertEqual(self.partner1.ref, self.partner2.ref) |
|||
self.partner2.ref = False |
|||
self.partner1.is_company = True |
|||
self.partner2.is_company = True |
|||
with self.assertRaises(ValidationError): |
|||
self.partner2.ref = 'same_ref' |
@ -0,0 +1,22 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa |
|||
Copyright 2017 Tecnativa - Vicent Cubells |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> |
|||
<odoo> |
|||
|
|||
<record id="view_company_form" model="ir.ui.view"> |
|||
<field name="name">Add partner_ref_unique field</field> |
|||
<field name="model">res.company</field> |
|||
<field name="inherit_id" ref="base.view_company_form"/> |
|||
<field name="arch" type="xml"> |
|||
<page name="configuration" position="inside"> |
|||
<group> |
|||
<group name="partner" string="Partners"> |
|||
<field name="partner_ref_unique"/> |
|||
</group> |
|||
</group> |
|||
</page> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue