Skip to content

Commit a9dd138

Browse files
committed
[MIG] purchase_tag: Migration to 18.0
1 parent 3afca64 commit a9dd138

File tree

7 files changed

+62
-33
lines changed

7 files changed

+62
-33
lines changed

purchase_tag/README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Purchase Tags
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
20-
:target: https://github.com/OCA/purchase-workflow/tree/17.0/purchase_tag
20+
:target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_tag
2121
:alt: OCA/purchase-workflow
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/purchase-workflow-17-0/purchase-workflow-17-0-purchase_tag
23+
:target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_tag
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -46,7 +46,7 @@ Bug Tracker
4646
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
4747
In case of trouble, please check there if your issue has already been reported.
4848
If you spotted it first, help us to smash it by providing a detailed and welcomed
49-
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_tag%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
49+
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_tag%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
5050

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

@@ -61,7 +61,7 @@ Authors
6161
Contributors
6262
------------
6363

64-
- Jasmin Solanki <[email protected]>
64+
- Jasmin Solanki <[email protected]>
6565

6666
Maintainers
6767
-----------
@@ -76,6 +76,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
7676
mission is to support the collaborative development of Odoo features and
7777
promote its widespread use.
7878

79-
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/17.0/purchase_tag>`_ project on GitHub.
79+
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/purchase_tag>`_ project on GitHub.
8080

8181
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

purchase_tag/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Purchase Tags",
77
"summary": "Allows to add multiple tags to purchase orders",
8-
"version": "17.0.1.1.1",
8+
"version": "18.0.1.0.0",
99
"author": "ForgeFlow, Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/purchase-workflow",
1111
"category": "Purchases",

purchase_tag/models/purchase_tag.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
from random import randint
66

7-
from odoo import _, api, fields, models
8-
from odoo.exceptions import ValidationError
7+
from odoo import api, fields, models
98

109

1110
class PurchaseTag(models.Model):
@@ -20,34 +19,24 @@ def _get_default_color(self):
2019
color = fields.Integer(default=lambda self: self._get_default_color())
2120
parent_id = fields.Many2one("purchase.tag", index=True, ondelete="cascade")
2221
child_ids = fields.One2many("purchase.tag", "parent_id")
23-
parent_path = fields.Char(index=True, unaccent=False)
22+
parent_path = fields.Char(index=True)
2423

2524
_sql_constraints = [
2625
("tag_name_uniq", "unique (name)", "Tag name already exists !"),
2726
]
2827

29-
def name_get(self):
30-
res = []
28+
def _compute_display_name(self):
3129
for tag in self:
3230
names = []
3331
current = tag
3432
while current:
35-
names.append(current.name)
33+
if current.name:
34+
names.append(current.name)
3635
current = current.parent_id
37-
res.append((tag.id, " / ".join(reversed(names))))
38-
return res
36+
display_name = " / ".join(reversed(names))
37+
tag.display_name = display_name
3938

4039
@api.model
41-
def _name_search(
42-
self, name="", domain=None, operator="ilike", limit=100, order=None
43-
):
44-
if name:
45-
domain = [("name", operator, name.split(" / ")[-1])] + list(domain or [])
46-
return super()._name_search(
47-
name=name, domain=domain, operator=operator, limit=limit, order=order
48-
)
49-
50-
@api.constrains("parent_id")
51-
def _check_parent_recursion(self):
52-
if not self._check_recursion("parent_id"):
53-
raise ValidationError(_("Tags cannot be recursive."))
40+
def _search_display_name(self, operator, value):
41+
domain = [("name", operator, value.split(" / ")[-1])]
42+
return domain

purchase_tag/static/description/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Purchase Tags</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:4fcd5e13e2e203e5e2591ebf21012a4ccae8a559594d518ccc40c71ae9440aad
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/purchase-workflow/tree/17.0/purchase_tag"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-17-0/purchase-workflow-17-0-purchase_tag"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_tag"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_tag"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module allows to add multiple tags to purchase orders</p>
374374
<p><strong>Table of contents</strong></p>
375375
<div class="contents local topic" id="contents">
@@ -393,7 +393,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
393393
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
394394
In case of trouble, please check there if your issue has already been reported.
395395
If you spotted it first, help us to smash it by providing a detailed and welcomed
396-
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_tag%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
396+
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_tag%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
397397
<p>Do not contact contributors directly about support or help with technical issues.</p>
398398
</div>
399399
<div class="section" id="credits">
@@ -419,7 +419,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
419419
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
420420
mission is to support the collaborative development of Odoo features and
421421
promote its widespread use.</p>
422-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/17.0/purchase_tag">OCA/purchase-workflow</a> project on GitHub.</p>
422+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_tag">OCA/purchase-workflow</a> project on GitHub.</p>
423423
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
424424
</div>
425425
</div>

purchase_tag/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_purchase_tag
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from odoo.exceptions import UserError
2+
3+
from odoo.addons.base.tests.common import BaseCommon
4+
5+
6+
class TestPurchaseTag(BaseCommon):
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
10+
PurchaseTag = cls.env["purchase.tag"]
11+
cls.tag_parent = PurchaseTag.create({"name": "Parent"})
12+
cls.tag_child = PurchaseTag.create(
13+
{"name": "Child", "parent_id": cls.tag_parent.id}
14+
)
15+
cls.tag_grandchild = PurchaseTag.create(
16+
{"name": "Grandchild", "parent_id": cls.tag_child.id}
17+
)
18+
19+
def test_display_name_computation(self):
20+
# Verify the hierarchical display_name.
21+
self.assertEqual(
22+
self.tag_grandchild.display_name, "Parent / Child / Grandchild"
23+
)
24+
self.assertEqual(self.tag_child.display_name, "Parent / Child")
25+
self.assertEqual(self.tag_parent.display_name, "Parent")
26+
27+
def test_name_search(self):
28+
# Perform a search using part of the display_name.
29+
results = self.env["purchase.tag"].name_search(
30+
name="Parent / Child / Grandchild"
31+
)
32+
self.assertTrue(results)
33+
self.assertEqual(results[0][0], self.tag_grandchild.id)
34+
self.assertEqual(results[0][1], "Parent / Child / Grandchild")
35+
36+
def test_recursion_error(self):
37+
# Trigger recursion to raise a UserError from Odoo's core.
38+
with self.assertRaisesRegex(UserError, "Recursion Detected."):
39+
self.tag_parent.write({"parent_id": self.tag_grandchild.id})

purchase_tag/views/purchase_tag_view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
<field name="name">purchase.tag.view.tree</field>
3333
<field name="model">purchase.tag</field>
3434
<field name="arch" type="xml">
35-
<tree>
35+
<list>
3636
<field name="name" />
3737
<field name="parent_id" optional="hide" />
3838
<field name="color" widget="color_picker" />
39-
</tree>
39+
</list>
4040
</field>
4141
</record>
4242

0 commit comments

Comments
 (0)