João Marques
4 years ago
committed by
Pedro M. Baeza
6 changed files with 63 additions and 79 deletions
-
11partner_ref_unique/__manifest__.py
-
7partner_ref_unique/hooks.py
-
11partner_ref_unique/models/res_company.py
-
23partner_ref_unique/models/res_partner.py
-
64partner_ref_unique/tests/test_res_partner_ref.py
-
12partner_ref_unique/views/res_company_view.xml
@ -1,67 +1,57 @@ |
|||||
# Copyright 2017 Tecnativa - Vicent Cubells |
# Copyright 2017 Tecnativa - Vicent Cubells |
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from odoo.tests import common |
|
||||
from odoo.exceptions import ValidationError |
from odoo.exceptions import ValidationError |
||||
|
from odoo.tests import common |
||||
|
|
||||
|
|
||||
class TestResPartnerRefUnique(common.SavepointCase): |
class TestResPartnerRefUnique(common.SavepointCase): |
||||
@classmethod |
@classmethod |
||||
def setUpClass(cls): |
def setUpClass(cls): |
||||
super(TestResPartnerRefUnique, cls).setUpClass() |
super(TestResPartnerRefUnique, cls).setUpClass() |
||||
cls.company = cls.env.ref('base.main_company') |
|
||||
cls.partner_obj = cls.env['res.partner'] |
|
||||
cls.partner1 = cls.partner_obj.create({ |
|
||||
'name': 'Partner1', |
|
||||
}) |
|
||||
cls.partner2 = cls.partner_obj.create({ |
|
||||
'name': 'Partner2', |
|
||||
}) |
|
||||
|
cls.company = cls.env.ref("base.main_company") |
||||
|
cls.partner_obj = cls.env["res.partner"] |
||||
|
cls.partner1 = cls.partner_obj.create({"name": "Partner1",}) |
||||
|
cls.partner2 = cls.partner_obj.create({"name": "Partner2",}) |
||||
|
|
||||
def test_check_ref_company(self): |
def test_check_ref_company(self): |
||||
# Test can create/modify partners with same ref |
# 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.company.partner_ref_unique = "none" |
||||
|
self.partner1.ref = "same_ref" |
||||
|
self.partner2.ref = "same_ref" |
||||
self.assertEqual(self.partner1.ref, self.partner2.ref) |
self.assertEqual(self.partner1.ref, self.partner2.ref) |
||||
# Here there shouldn't be any problem |
# Here there shouldn't be any problem |
||||
self.partner_obj.create({ |
|
||||
'name': 'other', |
|
||||
'ref': 'same_ref', |
|
||||
}) |
|
||||
|
self.partner_obj.create( |
||||
|
{"name": "other", "ref": "same_ref",} |
||||
|
) |
||||
self.partner2.ref = False |
self.partner2.ref = False |
||||
with self.assertRaises(ValidationError): |
with self.assertRaises(ValidationError): |
||||
self.company.partner_ref_unique = 'all' |
|
||||
|
self.company.partner_ref_unique = "all" |
||||
|
|
||||
def test_check_ref(self): |
def test_check_ref(self): |
||||
self.partner1.ref = 'same_ref' |
|
||||
|
self.partner1.ref = "same_ref" |
||||
# Test can't create/modify partner with same ref |
# Test can't create/modify partner with same ref |
||||
self.company.partner_ref_unique = 'all' |
|
||||
|
self.company.partner_ref_unique = "all" |
||||
with self.assertRaises(ValidationError): |
with self.assertRaises(ValidationError): |
||||
self.partner2.ref = 'same_ref' |
|
||||
|
self.partner2.ref = "same_ref" |
||||
with self.assertRaises(ValidationError): |
with self.assertRaises(ValidationError): |
||||
self.partner_obj.create({ |
|
||||
'name': 'other', |
|
||||
'ref': 'same_ref', |
|
||||
}) |
|
||||
|
self.partner_obj.create( |
||||
|
{"name": "other", "ref": "same_ref",} |
||||
|
) |
||||
# Test can't create/modify companies with same ref |
# Test can't create/modify companies with same ref |
||||
self.company.partner_ref_unique = 'companies' |
|
||||
self.partner2.ref = 'same_ref' |
|
||||
|
self.company.partner_ref_unique = "companies" |
||||
|
self.partner2.ref = "same_ref" |
||||
self.assertEqual(self.partner1.ref, self.partner2.ref) |
self.assertEqual(self.partner1.ref, self.partner2.ref) |
||||
self.partner2.ref = False |
self.partner2.ref = False |
||||
self.partner1.is_company = True |
self.partner1.is_company = True |
||||
self.partner2.is_company = True |
self.partner2.is_company = True |
||||
with self.assertRaises(ValidationError): |
with self.assertRaises(ValidationError): |
||||
self.partner2.ref = 'same_ref' |
|
||||
|
self.partner2.ref = "same_ref" |
||||
with self.assertRaises(ValidationError): |
with self.assertRaises(ValidationError): |
||||
self.partner_obj.create({ |
|
||||
'is_company': True, |
|
||||
'name': 'other', |
|
||||
'ref': 'same_ref', |
|
||||
}) |
|
||||
|
self.partner_obj.create( |
||||
|
{"is_company": True, "name": "other", "ref": "same_ref",} |
||||
|
) |
||||
# Here there shouldn't be any problem |
# Here there shouldn't be any problem |
||||
self.partner_obj.create({ |
|
||||
'is_company': False, |
|
||||
'name': 'other', |
|
||||
'ref': 'same_ref', |
|
||||
}) |
|
||||
|
self.partner_obj.create( |
||||
|
{"is_company": False, "name": "other", "ref": "same_ref",} |
||||
|
) |
@ -1,20 +1,18 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||
<!-- Copyright 2016 Antonio Espinosa |
<!-- Copyright 2016 Antonio Espinosa |
||||
Copyright 2017 Tecnativa - Vicent Cubells |
Copyright 2017 Tecnativa - Vicent Cubells |
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> |
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> |
||||
<odoo> |
<odoo> |
||||
|
|
||||
<record id="view_company_form" model="ir.ui.view"> |
|
||||
|
<record id="view_company_form" model="ir.ui.view"> |
||||
<field name="name">Add partner_ref_unique field</field> |
<field name="name">Add partner_ref_unique field</field> |
||||
<field name="model">res.company</field> |
<field name="model">res.company</field> |
||||
<field name="inherit_id" ref="base.view_company_form"/> |
|
||||
|
<field name="inherit_id" ref="base.view_company_form" /> |
||||
<field name="arch" type="xml"> |
<field name="arch" type="xml"> |
||||
<group name="social_media" position="before"> |
<group name="social_media" position="before"> |
||||
<group name="partner" string="Partners"> |
<group name="partner" string="Partners"> |
||||
<field name="partner_ref_unique"/> |
|
||||
|
<field name="partner_ref_unique" /> |
||||
</group> |
</group> |
||||
</group> |
</group> |
||||
</field> |
</field> |
||||
</record> |
|
||||
|
|
||||
|
</record> |
||||
</odoo> |
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue