Skip to content

Commit

Permalink
[MIG] mrp_tag: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Jan 10, 2025
1 parent 0992c53 commit 343c669
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 25 deletions.
15 changes: 8 additions & 7 deletions mrp_tag/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ MRP Tags
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/17.0/mrp_tag
:target: https://github.com/OCA/manufacture/tree/18.0/mrp_tag
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-17-0/manufacture-17-0-mrp_tag
:target: https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_tag
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=18.0
:alt: Try me on Runboat

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

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

Expand All @@ -61,8 +61,9 @@ Authors
Contributors
------------

- Jasmin Solanki <jasmin.solanki@forgeflow.com>
- Arturo Arribas <aarribas@alquemy.es>
- Jasmin Solanki <jasmin.solanki@forgeflow.com>
- Arturo Arribas <aarribas@alquemy.es>
- Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>

Maintainers
-----------
Expand All @@ -77,6 +78,6 @@ 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.

This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/17.0/mrp_tag>`_ project on GitHub.
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/18.0/mrp_tag>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion mrp_tag/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "MRP Tags",
"summary": "Allows to add multiple tags to Manufacturing Orders",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"category": "Purchases",
Expand Down
19 changes: 7 additions & 12 deletions mrp_tag/models/mrp_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _get_default_color(self):
color = fields.Integer(default=lambda self: self._get_default_color())
parent_id = fields.Many2one("mrp.tag", index=True, ondelete="cascade")
child_ids = fields.One2many("mrp.tag", "parent_id")
parent_path = fields.Char(index=True, unaccent=False)
parent_path = fields.Char(index=True)

_sql_constraints = [
("tag_name_uniq", "unique (name)", "Tag name already exists !"),
Expand All @@ -37,18 +37,13 @@ def _compute_display_name(self):
tag.display_name = " / ".join(reversed(names))

Check warning on line 37 in mrp_tag/models/mrp_tag.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/models/mrp_tag.py#L35-L37

Added lines #L35 - L37 were not covered by tests

@api.model
def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None):
if name:
domain = [("name", operator, name.split(" / ")[-1])] + list(domain or [])
return super()._name_search(
name=name,
domain=domain,
operator=operator,
limit=limit,
order=order,
)
def _search_display_name(self, operator, value):
domain = super()._search_display_name(operator, value)

Check warning on line 41 in mrp_tag/models/mrp_tag.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/models/mrp_tag.py#L41

Added line #L41 was not covered by tests
if value:
return [("name", operator, value.split(" / ")[-1])] + list(domain or [])
return domain

Check warning on line 44 in mrp_tag/models/mrp_tag.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/models/mrp_tag.py#L43-L44

Added lines #L43 - L44 were not covered by tests

@api.constrains("parent_id")
def _check_parent_recursion(self):
if not self._check_recursion("parent_id"):
if self._has_cycle("parent_id"):
raise ValidationError(_("Tags cannot be recursive."))

Check warning on line 49 in mrp_tag/models/mrp_tag.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/models/mrp_tag.py#L49

Added line #L49 was not covered by tests
1 change: 1 addition & 0 deletions mrp_tag/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Jasmin Solanki \<<jasmin.solanki@forgeflow.com>\>
- Arturo Arribas \<<aarribas@alquemy.es>\>
- Heliconia Solutions Pvt. Ltd. \<<https://www.heliconia.io>\>
7 changes: 4 additions & 3 deletions mrp_tag/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">MRP Tags</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b1286b744697667cb4aea4d9d615127f0a9032ebc94617e9b5b82d3815d121d9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/manufacture/tree/17.0/mrp_tag"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-17-0/manufacture-17-0-mrp_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/manufacture&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<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/manufacture/tree/18.0/mrp_tag"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_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/manufacture&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to add multiple tags to Manufacturing Orders</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -393,7 +393,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_tag%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_tag%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -409,6 +409,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Jasmin Solanki &lt;<a class="reference external" href="mailto:jasmin.solanki&#64;forgeflow.com">jasmin.solanki&#64;forgeflow.com</a>&gt;</li>
<li>Arturo Arribas &lt;<a class="reference external" href="mailto:aarribas&#64;alquemy.es">aarribas&#64;alquemy.es</a>&gt;</li>
<li>Heliconia Solutions Pvt. Ltd. &lt;<a class="reference external" href="https://www.heliconia.io">https://www.heliconia.io</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -420,7 +421,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/17.0/mrp_tag">OCA/manufacture</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/18.0/mrp_tag">OCA/manufacture</a> project on GitHub.</p>
<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>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions mrp_tag/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mrp_tag_test
95 changes: 95 additions & 0 deletions mrp_tag/tests/mrp_tag_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from odoo.exceptions import ValidationError
from odoo.tests import TransactionCase
from odoo.tools import mute_logger


class TestMrpTag(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

Check warning on line 9 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L9

Added line #L9 was not covered by tests

def setUp(self):
super().setUp()
self.MrpTag = self.env["mrp.tag"]

Check warning on line 13 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L12-L13

Added lines #L12 - L13 were not covered by tests

# Create test tags
self.tag_parent = self.MrpTag.create(

Check warning on line 16 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L16

Added line #L16 was not covered by tests
{
"name": "Production",
}
)

self.tag_child = self.MrpTag.create(

Check warning on line 22 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L22

Added line #L22 was not covered by tests
{
"name": "Assembly",
"parent_id": self.tag_parent.id,
}
)

self.tag_grandchild = self.MrpTag.create(

Check warning on line 29 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L29

Added line #L29 was not covered by tests
{
"name": "Electronics",
"parent_id": self.tag_child.id,
}
)

def test_compute_display_name(self):
"""Test the computation of hierarchical display names"""
self.assertEqual(self.tag_parent.display_name, "Production")
self.assertEqual(self.tag_child.display_name, "Production / Assembly")
self.assertEqual(

Check warning on line 40 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L38-L40

Added lines #L38 - L40 were not covered by tests
self.tag_grandchild.display_name, "Production / Assembly / Electronics"
)

def test_search_display_name(self):
"""Test searching tags by display name"""
# Test exact match
tags = self.MrpTag.search([("display_name", "=", "Production / Assembly")])
self.assertEqual(len(tags), 1)
self.assertEqual(tags[0], self.tag_child)

Check warning on line 49 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L47-L49

Added lines #L47 - L49 were not covered by tests

# Test partial match
tags = self.MrpTag.search([("display_name", "ilike", "Electronics")])
self.assertEqual(len(tags), 1)
self.assertEqual(tags[0], self.tag_grandchild)

Check warning on line 54 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L52-L54

Added lines #L52 - L54 were not covered by tests

# Test non-existent tag
tags = self.MrpTag.search([("display_name", "=", "Non-existent")])
self.assertEqual(len(tags), 0)

Check warning on line 58 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L57-L58

Added lines #L57 - L58 were not covered by tests

def test_recursive_constraint(self):
"""Test prevention of recursive tag hierarchies"""
with self.assertRaises(ValidationError), mute_logger("odoo.models"):

Check warning on line 62 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L62

Added line #L62 was not covered by tests
# Try to create a recursive hierarchy
self.tag_parent.write({"parent_id": self.tag_grandchild.id})

Check warning on line 64 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L64

Added line #L64 was not covered by tests

def test_create_tag_without_parent(self):
"""Test creation of tag without parent"""
tag = self.MrpTag.create({"name": "Standalone"})
self.assertEqual(tag.display_name, "Standalone")
self.assertFalse(tag.parent_id)

Check warning on line 70 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L68-L70

Added lines #L68 - L70 were not covered by tests

def test_update_parent(self):
"""Test updating tag parent"""
new_parent = self.MrpTag.create({"name": "NewParent"})

Check warning on line 74 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L74

Added line #L74 was not covered by tests

self.tag_child.write({"parent_id": new_parent.id})

Check warning on line 76 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L76

Added line #L76 was not covered by tests

self.assertEqual(self.tag_child.display_name, "NewParent / Assembly")
self.assertEqual(

Check warning on line 79 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L78-L79

Added lines #L78 - L79 were not covered by tests
self.tag_grandchild.display_name, "NewParent / Assembly / Electronics"
)

def test_delete_parent(self):
"""Test behavior when parent tag is deleted"""
self.tag_parent.unlink()

Check warning on line 85 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L85

Added line #L85 was not covered by tests

# Refresh records from database
self.tag_child.invalidate_cache()
self.tag_grandchild.invalidate_cache()

Check warning on line 89 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L88-L89

Added lines #L88 - L89 were not covered by tests

# Child tags should still exist but with updated display names
self.assertTrue(self.tag_child.exists())
self.assertTrue(self.tag_grandchild.exists())
self.assertEqual(self.tag_child.display_name, "Assembly")
self.assertEqual(self.tag_grandchild.display_name, "Assembly / Electronics")

Check warning on line 95 in mrp_tag/tests/mrp_tag_test.py

View check run for this annotation

Codecov / codecov/patch

mrp_tag/tests/mrp_tag_test.py#L92-L95

Added lines #L92 - L95 were not covered by tests
4 changes: 2 additions & 2 deletions mrp_tag/views/mrp_tag_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<field name="name">mrp.tag.view.tree</field>
<field name="model">mrp.tag</field>
<field name="arch" type="xml">
<tree name="Tags">
<list name="Tags">
<field name="name" />
<field name="parent_id" optional="hide" />
<field name="color" widget="color_picker" />
</tree>
</list>
</field>
</record>

Expand Down

0 comments on commit 343c669

Please sign in to comment.