forked from OCA/e-commerce
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_template_multi_link: Makes links bi-directional
fixes OCA#307
1 parent
266ae01
commit ae27763
Showing
16 changed files
with
892 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
product_template_multi_link/data/product_template_link_type.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2019 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo noupdate="1"> | ||
<record | ||
model="product.template.link.type" | ||
id="product_template_link_type_cross_selling" | ||
> | ||
<field name="name">Cross Selling</field> | ||
<field name="code">cross-selling</field> | ||
</record> | ||
<record | ||
model="product.template.link.type" | ||
id="product_template_link_type_up_selling" | ||
> | ||
<field name="name">Up Selling</field> | ||
<field name="code">up-selling</field> | ||
</record> | ||
</odoo> |
44 changes: 13 additions & 31 deletions
44
product_template_multi_link/demo/product_template_link.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
|
||
<record id="link_apple_1" model="product.template.link"> | ||
<field name="product_template_id" ref="product.product_product_7_product_template"/> | ||
<field name="linked_product_template_id" ref="product.product_product_9_product_template"/> | ||
<field name="link_type">cross_sell</field> | ||
</record> | ||
|
||
<record id="link_apple_2" model="product.template.link"> | ||
<field name="product_template_id" ref="product.product_product_9_product_template"/> | ||
<field name="linked_product_template_id" ref="product.product_product_7_product_template"/> | ||
<field name="link_type">cross_sell</field> | ||
<record id="link_cross_selling_1" model="product.template.link"> | ||
<field | ||
name="left_product_tmpl_id" | ||
ref="product.product_product_7_product_template" | ||
/> | ||
<field | ||
name="right_product_tmpl_id" | ||
ref="product.product_product_9_product_template" | ||
/> | ||
<field | ||
name="type_id" | ||
ref="product_template_multi_link.product_template_link_type_cross_selling" | ||
/> | ||
</record> | ||
|
||
<record id="link_membership_1" model="product.template.link"> | ||
<field name="product_template_id" ref="product.membership_2_product_template"/> | ||
<field name="linked_product_template_id" ref="product.membership_1_product_template"/> | ||
<field name="link_type">up_sell</field> | ||
</record> | ||
|
||
<record id="link_membership_2" model="product.template.link"> | ||
<field name="product_template_id" ref="product.membership_2_product_template"/> | ||
<field name="linked_product_template_id" ref="product.membership_0_product_template"/> | ||
<field name="link_type">up_sell</field> | ||
</record> | ||
|
||
<record id="link_membership_3" model="product.template.link"> | ||
<field name="product_template_id" ref="product.membership_1_product_template"/> | ||
<field name="linked_product_template_id" ref="product.membership_0_product_template"/> | ||
<field name="link_type">up_sell</field> | ||
</record> | ||
|
||
|
||
|
||
</odoo> | ||
|
15 changes: 15 additions & 0 deletions
15
product_template_multi_link/demo/product_template_link_type.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2019 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record | ||
model="product.template.link.type" | ||
id="product_template_link_type_demo_range" | ||
> | ||
<field name="is_symmetric" eval="0" /> | ||
<field name="name">Upper Range</field> | ||
<field name="inverse_name">Lower Range</field> | ||
<field name="code">upper-range</field> | ||
<field name="inverse_code">lower-range</field> | ||
</record> | ||
</odoo> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
from . import product_template | ||
from . import product_template_link | ||
from . import product_template_link_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
product_template_multi_link/models/product_template_link_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProductTemplateLinkType(models.Model): | ||
|
||
_name = "product.template.link.type" | ||
_description = "Product Template Link Type" | ||
|
||
name = fields.Char(required=True, translate=True) | ||
inverse_name = fields.Char( | ||
compute="_compute_inverse_name", | ||
inverse="_inverse_inverse_name", | ||
readonly=False, | ||
store=True, | ||
translate=True, | ||
) | ||
manual_inverse_name = fields.Char() | ||
is_symmetric = fields.Boolean( | ||
help="The relation meaning is the same from each side of the relation", | ||
default=True, | ||
) | ||
code = fields.Char( | ||
"Technical code", | ||
help="This code allows to provide a technical code to external" | ||
"systems identifying this link type", | ||
) | ||
inverse_code = fields.Char( | ||
"Technical code (inverse)", | ||
compute="_compute_inverse_code", | ||
inverse="_inverse_inverse_code", | ||
readonly=False, | ||
store=True, | ||
help="This code allows to provide a technical code to external" | ||
"systems identifying this link type", | ||
) | ||
manual_inverse_code = fields.Char() | ||
_sql_constraints = [ | ||
("name_uniq", "unique (name)", "Link type name already exists !"), | ||
( | ||
"inverse_name_uniq", | ||
"unique (inverse_name)", | ||
"Link type inverse name already exists !", | ||
), | ||
( | ||
"code_uniq", | ||
"EXCLUDE (code WITH =) WHERE (code is not null)", | ||
"Link code already exists !", | ||
), | ||
( | ||
"inverse_code_uniq", | ||
"EXCLUDE (inverse_code WITH =) WHERE (inverse_code is not null)", | ||
"Link inverse code already exists !", | ||
), | ||
] | ||
|
||
display_name = fields.Char(compute="_compute_display_name") | ||
|
||
@api.multi | ||
def _inverse_inverse_name(self): | ||
for record in self: | ||
record.manual_inverse_name = record.inverse_name | ||
|
||
@api.multi | ||
def _inverse_inverse_code(self): | ||
for record in self: | ||
record.manual_inverse_code = record.inverse_code | ||
|
||
@api.depends("name", "inverse_name") | ||
def _compute_display_name(self): | ||
for record in self: | ||
display_name = record.name | ||
if not record.is_symmetric: | ||
display_name = "{} / {}".format(record.inverse_name, record.name) | ||
record.display_name = display_name | ||
|
||
@api.depends("name", "is_symmetric") | ||
def _compute_inverse_name(self): | ||
for record in self: | ||
if record.is_symmetric: | ||
record.inverse_name = record.name | ||
else: | ||
record.inverse_name = record.manual_inverse_name | ||
|
||
@api.depends("code", "is_symmetric") | ||
def _compute_inverse_code(self): | ||
for record in self: | ||
if record.is_symmetric: | ||
record.inverse_code = record.code | ||
else: | ||
record.inverse_code = record.manual_inverse_code | ||
|
||
def write(self, vals): | ||
for record in self: | ||
is_symmetric = vals.get("is_symmetric", record.is_symmetric) | ||
v = vals.copy() | ||
if is_symmetric: | ||
v.pop("inverse_code", None) | ||
v.pop("inverse_name", None) | ||
r = super(ProductTemplateLinkType, record).write(v) | ||
return r |
23 changes: 23 additions & 0 deletions
23
product_template_multi_link/security/product_template_link_type.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2019 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record model="ir.model.access" id="product_template_link_type_access_read"> | ||
<field name="name">product.template.link.type access read</field> | ||
<field name="model_id" ref="model_product_template_link_type" /> | ||
<field name="group_id" ref="base.group_user" /> | ||
<field name="perm_read" eval="1" /> | ||
<field name="perm_create" eval="0" /> | ||
<field name="perm_write" eval="0" /> | ||
<field name="perm_unlink" eval="0" /> | ||
</record> | ||
<record model="ir.model.access" id="product_template_link_type_access_manage"> | ||
<field name="name">product.template.link.type access manager</field> | ||
<field name="model_id" ref="model_product_template_link_type" /> | ||
<field name="group_id" ref="sales_team.group_sale_manager" /> | ||
<field name="perm_read" eval="1" /> | ||
<field name="perm_create" eval="1" /> | ||
<field name="perm_write" eval="1" /> | ||
<field name="perm_unlink" eval="1" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from . import test_product_template_linker | ||
from . import test_product_template_link_type | ||
from . import test_product_template_link |
118 changes: 118 additions & 0 deletions
118
product_template_multi_link/tests/test_product_template_link.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.exceptions import ValidationError | ||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestProductTemplateLink(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TestProductTemplateLink, cls).setUpClass() | ||
cls.ProductTemplateLink = cls.env["product.template.link"] | ||
cls.product_product_1 = cls.env.ref("product.product_product_1") | ||
cls.product_product_2 = cls.env.ref("product.product_product_2") | ||
cls.link_type = cls.env.ref( | ||
"product_template_multi_link.product_template_link_type_cross_selling" | ||
) | ||
|
||
def test_01(self): | ||
""" | ||
Data: | ||
- 2 publication templates | ||
Test Case: | ||
- Try to create 2 links of same type | ||
Expected result: | ||
- ValidationError is raised | ||
""" | ||
link1 = self.ProductTemplateLink.create( | ||
{ | ||
"left_product_tmpl_id": self.product_product_1.id, | ||
"right_product_tmpl_id": self.product_product_2.id, | ||
"type_id": self.link_type.id, | ||
} | ||
) | ||
with self.assertRaises(ValidationError), self.env.cr.savepoint(): | ||
link1.copy() | ||
|
||
# create the same link but inverse ids | ||
with self.assertRaises(ValidationError), self.env.cr.savepoint(): | ||
self.ProductTemplateLink.create( | ||
{ | ||
"left_product_tmpl_id": self.product_product_2.id, | ||
"right_product_tmpl_id": self.product_product_1.id, | ||
"type_id": self.link_type.id, | ||
} | ||
) | ||
|
||
def test_02(self): | ||
""" | ||
Data: | ||
- 1 publication templates | ||
Test Case: | ||
- Try to create 1 link between the same product | ||
Expected result: | ||
- ValidationError is raised | ||
""" | ||
with self.assertRaises(ValidationError), self.env.cr.savepoint(): | ||
self.ProductTemplateLink.create( | ||
{ | ||
"left_product_tmpl_id": self.product_product_1.id, | ||
"right_product_tmpl_id": self.product_product_1.id, | ||
"type_id": self.link_type.id, | ||
} | ||
) | ||
|
||
def test_03(self): | ||
""" | ||
Data: | ||
- 2 publication templates | ||
Test Case: | ||
- Create 1 link between the 2 products | ||
Expected result: | ||
- The link is visible from the 2 products | ||
""" | ||
link1 = self.ProductTemplateLink.create( | ||
{ | ||
"left_product_tmpl_id": self.product_product_1.id, | ||
"right_product_tmpl_id": self.product_product_2.id, | ||
"type_id": self.link_type.id, | ||
} | ||
) | ||
self.assertEqual(link1, self.product_product_1.product_template_link_ids) | ||
|
||
self.assertEqual(link1, self.product_product_2.product_template_link_ids) | ||
|
||
def test_04(self): | ||
""" | ||
Data: | ||
- 2 publication templates | ||
Test Case: | ||
1 Create 1 link between the 2 products | ||
2 Unlik the link | ||
Expected result: | ||
1 The link is visible from the 2 products | ||
2 No link remains between the 2 products | ||
This test check the cache invalidation of the computed fields on the | ||
product.template | ||
""" | ||
link1 = self.ProductTemplateLink.create( | ||
{ | ||
"left_product_tmpl_id": self.product_product_1.id, | ||
"right_product_tmpl_id": self.product_product_2.id, | ||
"type_id": self.link_type.id, | ||
} | ||
) | ||
self.assertEqual(link1, self.product_product_1.product_template_link_ids) | ||
|
||
self.assertEqual(link1, self.product_product_2.product_template_link_ids) | ||
|
||
self.assertEqual(1, self.product_product_1.product_template_link_count) | ||
self.assertEqual(1, self.product_product_2.product_template_link_count) | ||
|
||
link1.unlink() | ||
self.assertFalse(self.product_product_1.product_template_link_ids) | ||
self.assertFalse(self.product_product_2.product_template_link_ids) | ||
self.assertEqual(0, self.product_product_1.product_template_link_count) | ||
self.assertEqual(0, self.product_product_2.product_template_link_count) |
262 changes: 262 additions & 0 deletions
262
product_template_multi_link/tests/test_product_template_link_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from psycopg2 import IntegrityError | ||
|
||
from odoo.tests import SavepointCase | ||
from odoo.tools import mute_logger | ||
|
||
|
||
class TestProductTemplateLinkType(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TestProductTemplateLinkType, cls).setUpClass() | ||
cls.LinkType = cls.env["product.template.link.type"] | ||
cls.link_type_cross_selling = cls.env.ref( | ||
"product_template_multi_link.product_template_link_type_cross_selling" | ||
) | ||
cls.link_type_range = cls.env.ref( | ||
"product_template_multi_link.product_template_link_type_demo_range" | ||
) | ||
cls.symmetric_link_without_code = cls.LinkType.create( | ||
{"name": "symmetric_link_without_code"} | ||
) | ||
cls.symmetric_link_with_code = cls.LinkType.create( | ||
{ | ||
"name": "symmetric_link_with_code-name", | ||
"code": "symmetric_link_with_code-code", | ||
} | ||
) | ||
cls.asymmetric_link_without_inverse_code = cls.LinkType.create( | ||
{ | ||
"is_symmetric": False, | ||
"name": "asymmetric_link_without_code-name", | ||
"inverse_name": "asymmetric_link_without_code-inverse_name", | ||
} | ||
) | ||
|
||
cls.asymmetric_link_with_inverse_code = cls.LinkType.create( | ||
{ | ||
"is_symmetric": False, | ||
"name": "asymmetric_link_with_code-name", | ||
"inverse_name": "asymmetric_link_with_code-inverse_name", | ||
"inverse_code": "asymmetric_link_with_code-inverse_code", | ||
} | ||
) | ||
|
||
def test_0(self): | ||
""" | ||
Data: | ||
None | ||
Test case: | ||
Create a link type by providing only the name | ||
Expected Result: | ||
by default link is symmetric | ||
inverse_name is computed | ||
inverse_name is equal to name | ||
code is false (not provided) | ||
inverse_code is false | ||
""" | ||
link_type = self.LinkType.create({"name": "my type"}) | ||
self.assertTrue(link_type.is_symmetric) | ||
self.assertTrue(link_type.name) | ||
self.assertEqual(link_type.name, link_type.inverse_name) | ||
self.assertFalse(link_type.code) | ||
self.assertFalse(link_type.inverse_code) | ||
|
||
def test_1(self): | ||
""" | ||
Data: | ||
None | ||
Test case: | ||
Create a link type by providing only the name and the code | ||
Expected Result: | ||
by default link is symmetric | ||
inverse_name is computed | ||
inverse_name is equal to name | ||
inverse_code is computed | ||
inverse_code is equal to code | ||
""" | ||
link_type = self.LinkType.create({"name": "my type", "code": "my-code"}) | ||
self.assertTrue(link_type.is_symmetric) | ||
self.assertEqual(link_type.name, "my type") | ||
self.assertEqual(link_type.code, "my-code") | ||
self.assertEqual(link_type.name, link_type.inverse_name) | ||
self.assertEqual(link_type.code, link_type.inverse_code) | ||
|
||
@mute_logger("odoo.sql_db") | ||
def test_2(self): | ||
""" | ||
Data: | ||
None | ||
Test case: | ||
Create a link type without providing the name | ||
Expected Result: | ||
Exception is raised | ||
""" | ||
with self.assertRaises(IntegrityError), self.env.cr.savepoint(): | ||
self.LinkType.create( | ||
{ | ||
"inverse_name": "my type", | ||
"is_symmetric": False, | ||
"code": "my_code", | ||
"inverse_code": "my_inverse_code", | ||
} | ||
) | ||
|
||
def test_3(self): | ||
""" | ||
Data: | ||
An existing symmetric link type | ||
Test case: | ||
Update the name | ||
Expected Result: | ||
inverse_name is still equal to name | ||
""" | ||
self.assertEqual( | ||
self.link_type_cross_selling.name, self.link_type_cross_selling.inverse_name | ||
) | ||
self.link_type_cross_selling.write({"name": "new name"}) | ||
self.assertEqual(self.link_type_cross_selling.name, "new name") | ||
self.assertEqual( | ||
self.link_type_cross_selling.name, self.link_type_cross_selling.inverse_name | ||
) | ||
|
||
def test_4(self): | ||
""" | ||
Data: | ||
An existing symmetric link type | ||
Test case: | ||
Update the code | ||
Expected Result: | ||
inverse_code is still equal to code | ||
""" | ||
self.assertEqual( | ||
self.link_type_cross_selling.code, self.link_type_cross_selling.inverse_code | ||
) | ||
self.link_type_cross_selling.write({"code": "new-code"}) | ||
self.assertEqual(self.link_type_cross_selling.code, "new-code") | ||
self.assertEqual( | ||
self.link_type_cross_selling.code, self.link_type_cross_selling.inverse_code | ||
) | ||
|
||
def test_5(self): | ||
""" | ||
Data: | ||
An existing symmetric link type | ||
Test case: | ||
Update the inverse_name | ||
Update the inverse_code | ||
Expected Result: | ||
inverse_name and inverse_code are not updated | ||
""" | ||
self.assertEqual( | ||
self.link_type_cross_selling.name, self.link_type_cross_selling.inverse_name | ||
) | ||
self.assertEqual( | ||
self.link_type_cross_selling.code, self.link_type_cross_selling.inverse_code | ||
) | ||
inverse_name = self.link_type_cross_selling.inverse_name | ||
inverse_code = self.link_type_cross_selling.inverse_code | ||
self.link_type_cross_selling.write( | ||
{ | ||
"inverse_name": "new " + inverse_name, | ||
"inverse_code": "new " + inverse_code, | ||
} | ||
) | ||
self.assertEqual(self.link_type_cross_selling.inverse_name, inverse_name) | ||
self.assertEqual(self.link_type_cross_selling.inverse_code, inverse_code) | ||
|
||
def test_6(self): | ||
""" | ||
Data: | ||
An existing symmetric link type | ||
Test case: | ||
Update the inverse_name with name != inverse_name, | ||
code != inverse_code and make it asymmetric | ||
Expected Result: | ||
inverse_name is no more equal to name and | ||
the code is not more equald to inverse_code | ||
""" | ||
self.assertEqual( | ||
self.link_type_cross_selling.name, self.link_type_cross_selling.inverse_name | ||
) | ||
self.assertEqual( | ||
self.link_type_cross_selling.code, self.link_type_cross_selling.inverse_code | ||
) | ||
self.link_type_cross_selling.write( | ||
{ | ||
"is_symmetric": False, | ||
"inverse_name": "new inverse name", | ||
"inverse_code": "new inverse code", | ||
} | ||
) | ||
self.assertEqual(self.link_type_cross_selling.inverse_name, "new inverse name") | ||
self.assertEqual(self.link_type_cross_selling.inverse_code, "new inverse code") | ||
|
||
def test_7(self): | ||
""" | ||
Data: | ||
An existing asymmetric link with inverse_code != code | ||
and inverse_name != name | ||
Test case: | ||
1 Make it symmetric | ||
Expected Result: | ||
invsere_code=code and inverse_name=name | ||
""" | ||
self.assertFalse(self.link_type_range.is_symmetric) | ||
self.assertNotEqual( | ||
self.link_type_range.name, self.link_type_range.inverse_name | ||
) | ||
self.assertNotEqual( | ||
self.link_type_range.code, self.link_type_range.inverse_code | ||
) | ||
self.link_type_range.write({"is_symmetric": True}) | ||
self.assertEqual(self.link_type_range.name, self.link_type_range.inverse_name) | ||
self.assertEqual(self.link_type_range.code, self.link_type_range.inverse_code) | ||
|
||
@mute_logger("odoo.sql_db") | ||
def test_8(self): | ||
""" | ||
Data: | ||
symmetric link type without code | ||
symmetric link with code | ||
asymmetric link type without inverse_code | ||
asymmetric link type with inverse_code | ||
Test case: | ||
1 create a new link type with the same name without code | ||
1 create a new link type with the same name | ||
1 create a new link type with the same code | ||
1 create a new link type with the same inverse_name | ||
Expected Result: | ||
Intergrity Error | ||
""" | ||
with self.assertRaises(IntegrityError), self.env.cr.savepoint(): | ||
self.LinkType.create({"name": self.symmetric_link_without_code.name}) | ||
|
||
with self.assertRaises(IntegrityError), self.env.cr.savepoint(): | ||
self.LinkType.create( | ||
{ | ||
"name": self.symmetric_link_with_code.name + "test_8", | ||
"code": self.symmetric_link_with_code.code, | ||
} | ||
) | ||
with self.assertRaises(IntegrityError), self.env.cr.savepoint(): | ||
inverse_name = self.asymmetric_link_without_inverse_code.inverse_name | ||
self.LinkType.create( | ||
{ | ||
"name": self.asymmetric_link_without_inverse_code.name + "test_8", | ||
"inverse_name": inverse_name, | ||
} | ||
) | ||
with self.assertRaises(IntegrityError), self.env.cr.savepoint(): | ||
self.LinkType.create( | ||
{ | ||
"name": self.asymmetric_link_with_inverse_code.name + "test_8", | ||
"inverse_name": self.asymmetric_link_with_inverse_code.inverse_name | ||
+ "test_8", | ||
"inverse_code": self.asymmetric_link_with_inverse_code.inverse_code, | ||
} | ||
) |
40 changes: 40 additions & 0 deletions
40
product_template_multi_link/views/product_template_link_type.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2019 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record model="ir.ui.view" id="product_template_link_type_tree_view"> | ||
<field | ||
name="name" | ||
>product.template.link.type.tree (in product_template_multi_link)</field> | ||
<field name="model">product.template.link.type</field> | ||
<field name="arch" type="xml"> | ||
<tree editable="top"> | ||
<field name="is_symmetric" /> | ||
<field name="name" /> | ||
<field | ||
name="inverse_name" | ||
required="1" | ||
attrs="{'readonly': [('is_symmetric', '=', True)]}" | ||
/> | ||
<field name="code" /> | ||
<field | ||
name="inverse_code" | ||
attrs="{'readonly': [('is_symmetric', '=', True)]}" | ||
/> | ||
</tree> | ||
</field> | ||
</record> | ||
<record model="ir.actions.act_window" id="product_template_link_type_act_window"> | ||
<field name="name">Product Template Link Type</field> | ||
<field name="res_model">product.template.link.type</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="domain">[]</field> | ||
<field name="context">{}</field> | ||
</record> | ||
<record model="ir.ui.menu" id="product_template_link_type_menu"> | ||
<field name="name">Product Template Link Type</field> | ||
<field name="parent_id" ref="sale.prod_config_main" /> | ||
<field name="action" ref="product_template_link_type_act_window" /> | ||
<field name="sequence" eval="16" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters