Skip to content

Commit

Permalink
[MIG] project_task_stage_state: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Dec 26, 2024
1 parent 2edb256 commit b48ad67
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 105 deletions.
28 changes: 15 additions & 13 deletions project_task_stage_state/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Add State field to Project Stages
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github
:target: https://github.com/OCA/project/tree/17.0/project_task_stage_state
:target: https://github.com/OCA/project/tree/18.0/project_task_stage_state
:alt: OCA/project
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/project-17-0/project-17-0-project_task_stage_state
:target: https://translation.odoo-community.org/projects/project-18-0/project-18-0-project_task_stage_state
: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/project&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/project&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -60,7 +60,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/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/project/issues/new?body=module:%20project_task_stage_state%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_task_stage_state%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 @@ -75,15 +75,17 @@ Authors
Contributors
------------

- Daniel Reis
- Rodrigo Ferreira <[email protected]>
- Anand Kansagra <[email protected]>
- Saran Lim. <[email protected]>
- Nattapol Sinsuphan<[email protected]>
- Manuel Regidor <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:
- Daniel Reis
- Rodrigo Ferreira <[email protected]>
- Anand Kansagra <[email protected]>
- Saran Lim. <[email protected]>
- Nattapol Sinsuphan<[email protected]>
- Manuel Regidor <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:

- Víctor Martínez
- Víctor Martínez

- ``Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>``\ \_

Maintainers
-----------
Expand All @@ -98,6 +100,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/project <https://github.com/OCA/project/tree/17.0/project_task_stage_state>`_ project on GitHub.
This module is part of the `OCA/project <https://github.com/OCA/project/tree/18.0/project_task_stage_state>`_ 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 project_task_stage_state/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Add State field to Project Stages",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"category": "Project Management",
"summary": "Restore State attribute removed from Project Stages in 8.0",
"author": "Daniel Reis, Odoo Community Association (OCA)",
Expand Down
19 changes: 0 additions & 19 deletions project_task_stage_state/migrations/17.0.1.0.0/post-migration.py

This file was deleted.

60 changes: 0 additions & 60 deletions project_task_stage_state/migrations/17.0.1.0.0/pre-migration.py

This file was deleted.

1 change: 1 addition & 0 deletions project_task_stage_state/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- Manuel Regidor \<<[email protected]>\>
- [Tecnativa](https://www.tecnativa.com):
- Víctor Martínez
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`_
7 changes: 4 additions & 3 deletions project_task_stage_state/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Add State field to Project Stages</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a9118b6b9c0875ec871c9c4e8ee43f0acc4ce7c9db1a1432bf70a96c02d8b1d4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/project/tree/17.0/project_task_stage_state"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/project-17-0/project-17-0-project_task_stage_state"><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/project&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/project/tree/18.0/project_task_stage_state"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/project-18-0/project-18-0-project_task_stage_state"><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/project&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 associates a state to a stage, so that when the stage of a
task is changed, the state is also changed..</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -408,7 +408,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/project/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/project/issues/new?body=module:%20project_task_stage_state%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/project/issues/new?body=module:%20project_task_stage_state%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 @@ -432,6 +432,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Víctor Martínez</li>
</ul>
</li>
<li><tt class="docutils literal">Heliconia Solutions Pvt. Ltd. <span class="pre">&lt;https://www.heliconia.io&gt;</span></tt>_</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -443,7 +444,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">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/project/tree/17.0/project_task_stage_state">OCA/project</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/18.0/project_task_stage_state">OCA/project</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
71 changes: 62 additions & 9 deletions project_task_stage_state/tests/test_project_task_stage_state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.addons.base.tests.common import BaseCommon


Expand All @@ -11,6 +9,12 @@ def setUpClass(cls):
cls.stage_in_progress = cls.env.ref("project.project_stage_1")
cls.stage_done = cls.env.ref("project.project_stage_2")
cls.stage_canceled = cls.env.ref("project.project_stage_3")

# Set the task_state explicitly in the stages for proper testing
cls.stage_in_progress.write({"task_state": "01_in_progress"})
cls.stage_done.write({"task_state": "1_done"})
cls.stage_canceled.write({"task_state": "1_canceled"})

cls.task = cls.env["project.task"].create(
{
"name": "Test task",
Expand All @@ -20,16 +24,65 @@ def setUpClass(cls):
}
)

def test_project_task_stages(self):
# Change to done: the state is changed
def test_task_state_is_set_when_stage_has_task_state(self):
# Test: Change to done, the state should update to "1_done"
self.task.write({"stage_id": self.stage_done.id})
self.assertEqual(self.task.state, "1_done")
# Change to cancelled: the state is changed

# Test: Change to canceled, the state should update to "1_canceled"
self.task.write({"stage_id": self.stage_canceled.id})
self.assertEqual(self.task.state, "1_canceled")
# Change to new: the state is NOT changed
self.task.write({"stage_id": self.stage_new.id})
self.assertEqual(self.task.state, "1_canceled")
# Change to in progress: the state is changed

# Test: Change to in progress, the state should update to "01_in_progress"
self.task.write({"stage_id": self.stage_in_progress.id})
self.assertEqual(self.task.state, "01_in_progress")

def test_task_states_dynamic_selection(self):
# Test: Ensure the task_state field dynamically fetches the correct selection
expected_states = dict(
self.env["project.task"].fields_get(allfields=["state"])["state"][
"selection"
]
)
self.assertIn(self.stage_done.task_state, expected_states)
self.assertIn(self.stage_in_progress.task_state, expected_states)
self.assertIn(self.stage_canceled.task_state, expected_states)

def test_get_task_states(self):
# Test: Ensure _get_task_states fetches the correct states dynamically
task_states = self.stage_done._get_task_states() # Returns a list of tuples
expected_states = dict(
self.env["project.task"].fields_get(allfields=["state"])["state"][
"selection"
]
) # Dictionary of expected states

# Assert that all keys from task_states exist in expected_states
task_state_keys = [key for key, _ in task_states]
self.assertEqual(len(task_state_keys), len(expected_states))
for state_key in task_state_keys:
self.assertIn(state_key, expected_states)

def test_task_state_is_none(self):
# Test: Ensure task_state can be None and doesn't alter the task state
self.stage_in_progress.write({"task_state": None})
self.task.write({"stage_id": self.stage_in_progress.id})
self.assertEqual(self.task.state, "01_in_progress") # No change expected

def test_get_task_states_edge_cases(self):
# Temporarily override the 'state' field's selection
original_selection = self.env["project.task"]._fields["state"].selection
try:
# Set a custom selection for testing edge cases
self.env["project.task"]._fields["state"].selection = [
("edge_case_1", "Edge Case 1"),
("edge_case_2", "Edge Case 2"),
]

# Call _get_task_states and validate it includes the edge cases
task_states = self.stage_done._get_task_states()
self.assertIn(("edge_case_1", "Edge Case 1"), task_states)
self.assertIn(("edge_case_2", "Edge Case 2"), task_states)
finally:
# Restore the original selection after the test
self.env["project.task"]._fields["state"].selection = original_selection

0 comments on commit b48ad67

Please sign in to comment.