diff --git a/project_task_personal_stage_auto_fold/README.rst b/project_task_personal_stage_auto_fold/README.rst new file mode 100644 index 0000000000..0b09988635 --- /dev/null +++ b/project_task_personal_stage_auto_fold/README.rst @@ -0,0 +1,113 @@ +===================================== +Project Task Personal Stage auto Fold +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ab59448fc27c5eebf9d0731a3a219ba63741d244c865b66c1c16e109aede491d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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_personal_stage_auto_fold + :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_personal_stage_auto_fold + :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 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When you close a task, its personal stage will change as well. + +This module simplifies to close or to cancel a task from the project +stage and the personal stage. + +In the case a task is assigned to more than one user, only the personal +task stage of the user will be updated. + +Notice: This module don't change the project task stage from the +personal task stage. It is intended so no change about this +functionality is desired or required. Furthermore, also is intended that +only the personal stage of the user who finish the task with the project +task stage will be update. So the other users assigned to the task have +to update the personal task stage manually when they finish it + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +The task stages "Done" and "Canceled" must match the same name as the +equivalent personal stages. + +The checkbox “Closing stage” must be checked in the stage configuration. + +Usage +===== + +1. Go to Projects > Select one > Select a task assigned to you +2. Change the stage to Done or to Canceled +3. Go to My Tasks > Select the same task +4. As you can see, the personal stage has also changed + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Moduon + +Contributors +------------ + +- `Moduon `__: + + - Eduardo de Miguel + +- `C2i Change 2 improve `__: + + - Eduardo Magdalena + +- Nikul Chaudhary + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/project_task_personal_stage_auto_fold/__init__.py b/project_task_personal_stage_auto_fold/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/project_task_personal_stage_auto_fold/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/project_task_personal_stage_auto_fold/__manifest__.py b/project_task_personal_stage_auto_fold/__manifest__.py new file mode 100644 index 0000000000..398554a4c2 --- /dev/null +++ b/project_task_personal_stage_auto_fold/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2022 Moduon - Eduardo de Miguel +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Project Task Personal Stage auto Fold", + "summary": "Moves task to the first fold personal stage when done", + "version": "17.0.1.0.0", + "category": "Project", + "website": "https://github.com/OCA/project", + "author": "Moduon, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["project"], + "data": [], + "installable": True, +} diff --git a/project_task_personal_stage_auto_fold/i18n/es.po b/project_task_personal_stage_auto_fold/i18n/es.po new file mode 100644 index 0000000000..5f2402bd0b --- /dev/null +++ b/project_task_personal_stage_auto_fold/i18n/es.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_task_personal_stage_auto_fold +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-09-07 16:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: project_task_personal_stage_auto_fold +#: model:ir.model,name:project_task_personal_stage_auto_fold.model_project_task +msgid "Task" +msgstr "Tarea" diff --git a/project_task_personal_stage_auto_fold/i18n/hr.po b/project_task_personal_stage_auto_fold/i18n/hr.po new file mode 100644 index 0000000000..5f9e650746 --- /dev/null +++ b/project_task_personal_stage_auto_fold/i18n/hr.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_task_personal_stage_auto_fold +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-02-15 17:23+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: project_task_personal_stage_auto_fold +#: model:ir.model,name:project_task_personal_stage_auto_fold.model_project_task +msgid "Task" +msgstr "Zadatak" diff --git a/project_task_personal_stage_auto_fold/i18n/it.po b/project_task_personal_stage_auto_fold/i18n/it.po new file mode 100644 index 0000000000..66067fdba1 --- /dev/null +++ b/project_task_personal_stage_auto_fold/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_task_personal_stage_auto_fold +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-04-10 21:22+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: project_task_personal_stage_auto_fold +#: model:ir.model,name:project_task_personal_stage_auto_fold.model_project_task +msgid "Task" +msgstr "Lavoro" diff --git a/project_task_personal_stage_auto_fold/i18n/project_task_personal_stage_auto_fold.pot b/project_task_personal_stage_auto_fold/i18n/project_task_personal_stage_auto_fold.pot new file mode 100644 index 0000000000..6e1143b4af --- /dev/null +++ b/project_task_personal_stage_auto_fold/i18n/project_task_personal_stage_auto_fold.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_task_personal_stage_auto_fold +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: project_task_personal_stage_auto_fold +#: model:ir.model,name:project_task_personal_stage_auto_fold.model_project_task +msgid "Task" +msgstr "" diff --git a/project_task_personal_stage_auto_fold/i18n/pt_BR.po b/project_task_personal_stage_auto_fold/i18n/pt_BR.po new file mode 100644 index 0000000000..0c4e11c851 --- /dev/null +++ b/project_task_personal_stage_auto_fold/i18n/pt_BR.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_task_personal_stage_auto_fold +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-07-30 14:10+0000\n" +"Last-Translator: Adriano Prado \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: project_task_personal_stage_auto_fold +#: model:ir.model,name:project_task_personal_stage_auto_fold.model_project_task +msgid "Task" +msgstr "Tarefa" diff --git a/project_task_personal_stage_auto_fold/models/__init__.py b/project_task_personal_stage_auto_fold/models/__init__.py new file mode 100644 index 0000000000..edf2d36b9c --- /dev/null +++ b/project_task_personal_stage_auto_fold/models/__init__.py @@ -0,0 +1 @@ +from . import project_task diff --git a/project_task_personal_stage_auto_fold/models/project_task.py b/project_task_personal_stage_auto_fold/models/project_task.py new file mode 100644 index 0000000000..becb25995e --- /dev/null +++ b/project_task_personal_stage_auto_fold/models/project_task.py @@ -0,0 +1,41 @@ +from odoo import models + + +class Task(models.Model): + _inherit = "project.task" + + def write(self, vals): + result = super().write(vals) + stage_id = vals.get("stage_id") + if stage_id and self.env["project.task.type"].browse(stage_id).fold: + self._fold_personal_stage_task() + return result + + def _fold_personal_stage_task(self): + """ + Assigns a folded personal stage to tasks when they are moved to a folded stage. + The function finds all folded stages associated with the current user and + applies the best matching personal stage based on the task's stage name. If + no exact match is found, the first available folded personal stage is assigned. + """ + + # Find all folded personal stages + folded_stages = ( + self.env["project.task.type"] + .search( + [ + ("user_id", "=", self.env.user.id), + ("fold", "=", True), + ], + ) + .sorted(lambda ptt: ptt.fold, reverse=True) + ) + # Allow to find personal stage with same name as shared stage + stage_by_name = {stage.name: stage for stage in folded_stages} + # Apply best matching personal stage + default_stage = folded_stages[0] + for task in self: + task.personal_stage_type_id = stage_by_name.get( + task.stage_id.name, + default_stage, + ) diff --git a/project_task_personal_stage_auto_fold/pyproject.toml b/project_task_personal_stage_auto_fold/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/project_task_personal_stage_auto_fold/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/project_task_personal_stage_auto_fold/readme/CONFIGURE.md b/project_task_personal_stage_auto_fold/readme/CONFIGURE.md new file mode 100644 index 0000000000..6ffe836d9e --- /dev/null +++ b/project_task_personal_stage_auto_fold/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +The task stages "Done" and "Canceled" must match the same name as the +equivalent personal stages. + +The checkbox “Closing stage” must be checked in the stage configuration. diff --git a/project_task_personal_stage_auto_fold/readme/CONTRIBUTORS.md b/project_task_personal_stage_auto_fold/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..d965d0da1e --- /dev/null +++ b/project_task_personal_stage_auto_fold/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- [Moduon](http://moduon.team/): + - Eduardo de Miguel \<\> +- [C2i Change 2 improve](http://c2i.es/): + - Eduardo Magdalena \<\> + +- Nikul Chaudhary \<\> + diff --git a/project_task_personal_stage_auto_fold/readme/DESCRIPTION.md b/project_task_personal_stage_auto_fold/readme/DESCRIPTION.md new file mode 100644 index 0000000000..b9f1c9f676 --- /dev/null +++ b/project_task_personal_stage_auto_fold/readme/DESCRIPTION.md @@ -0,0 +1,14 @@ +When you close a task, its personal stage will change as well. + +This module simplifies to close or to cancel a task from the project +stage and the personal stage. + +In the case a task is assigned to more than one user, only the personal +task stage of the user will be updated. + +Notice: This module don't change the project task stage from the +personal task stage. It is intended so no change about this +functionality is desired or required. Furthermore, also is intended that +only the personal stage of the user who finish the task with the project +task stage will be update. So the other users assigned to the task have +to update the personal task stage manually when they finish it diff --git a/project_task_personal_stage_auto_fold/readme/USAGE.md b/project_task_personal_stage_auto_fold/readme/USAGE.md new file mode 100644 index 0000000000..1316c4fa2e --- /dev/null +++ b/project_task_personal_stage_auto_fold/readme/USAGE.md @@ -0,0 +1,4 @@ +1. Go to Projects \> Select one \> Select a task assigned to you +2. Change the stage to Done or to Canceled +3. Go to My Tasks \> Select the same task +4. As you can see, the personal stage has also changed diff --git a/project_task_personal_stage_auto_fold/static/description/icon.png b/project_task_personal_stage_auto_fold/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/project_task_personal_stage_auto_fold/static/description/icon.png differ diff --git a/project_task_personal_stage_auto_fold/static/description/index.html b/project_task_personal_stage_auto_fold/static/description/index.html new file mode 100644 index 0000000000..efeff9463b --- /dev/null +++ b/project_task_personal_stage_auto_fold/static/description/index.html @@ -0,0 +1,455 @@ + + + + + +Project Task Personal Stage auto Fold + + + +
+

Project Task Personal Stage auto Fold

+ + +

Beta License: AGPL-3 OCA/project Translate me on Weblate Try me on Runboat

+

When you close a task, its personal stage will change as well.

+

This module simplifies to close or to cancel a task from the project +stage and the personal stage.

+

In the case a task is assigned to more than one user, only the personal +task stage of the user will be updated.

+

Notice: This module don’t change the project task stage from the +personal task stage. It is intended so no change about this +functionality is desired or required. Furthermore, also is intended that +only the personal stage of the user who finish the task with the project +task stage will be update. So the other users assigned to the task have +to update the personal task stage manually when they finish it

+

Table of contents

+ +
+

Configuration

+

The task stages “Done” and “Canceled” must match the same name as the +equivalent personal stages.

+

The checkbox “Closing stage” must be checked in the stage configuration.

+
+
+

Usage

+
    +
  1. Go to Projects > Select one > Select a task assigned to you
  2. +
  3. Change the stage to Done or to Canceled
  4. +
  5. Go to My Tasks > Select the same task
  6. +
  7. As you can see, the personal stage has also changed
  8. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Moduon
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

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

+
+
+
+ + diff --git a/project_task_personal_stage_auto_fold/tests/__init__.py b/project_task_personal_stage_auto_fold/tests/__init__.py new file mode 100644 index 0000000000..dbe166ca5b --- /dev/null +++ b/project_task_personal_stage_auto_fold/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_personal_stages diff --git a/project_task_personal_stage_auto_fold/tests/test_personal_stages.py b/project_task_personal_stage_auto_fold/tests/test_personal_stages.py new file mode 100644 index 0000000000..a587aa5f62 --- /dev/null +++ b/project_task_personal_stage_auto_fold/tests/test_personal_stages.py @@ -0,0 +1,142 @@ +# Copyright 2022 Moduon - Eduardo de Miguel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import TransactionCase + + +class TestAutoFoldPersonalStages(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + user_group_employee = cls.env.ref("base.group_user") + user_group_project_user = cls.env.ref("project.group_project_user") + user_group_project_manager = cls.env.ref("project.group_project_manager") + cls.partner_1 = cls.env["res.partner"].create( + {"name": "Valid Lelitre", "email": "valid.lelitre@agrolait.com"} + ) + # Test users to use through the various tests + Users = cls.env["res.users"].with_context(no_reset_password=True) + cls.user_projectuser = Users.create( + { + "name": "Armande ProjectUser", + "login": "armandel", + "password": "armandel", + "email": "armande.projectuser@example.com", + "groups_id": [ + (6, 0, [user_group_employee.id, user_group_project_user.id]) + ], + } + ) + cls.user_projectmanager = Users.create( + { + "name": "Bastien ProjectManager", + "login": "bastien", + "email": "bastien.projectmanager@example.com", + "groups_id": [ + (6, 0, [user_group_employee.id, user_group_project_manager.id]) + ], + } + ) + # Test 'Pigs' project + cls.project_pigs = ( + cls.env["project.project"] + .with_context(mail_create_nolog=True) + .create( + { + "name": "Pigs", + "privacy_visibility": "employees", + "alias_name": "project+pigs", + "partner_id": cls.partner_1.id, + } + ) + ) + cls.project_task_stages = cls.env["project.task.type"].create( + [ + {"sequence": 1, "name": "New"}, + {"sequence": 2, "name": "In progress"}, + {"sequence": 3, "name": "Finished", "fold": True}, + {"sequence": 4, "name": "Canceled", "fold": True}, + ] + ) + cls.project_pigs.type_ids = [(6, 0, cls.project_task_stages.ids)] + cls.task_3 = cls.env["project.task"].create( + { + "name": "Multiple Assigned Task", + "user_ids": [ + (6, 0, [cls.user_projectmanager.id, cls.user_projectuser.id]) + ], + "project_id": cls.project_pigs.id, + } + ) + cls.task_3.with_user(cls.user_projectmanager)._compute_personal_stage_id() + cls.task_3.with_user(cls.user_projectuser)._compute_personal_stage_id() + + def setUp(self): + """Save user_projectuser initial personal stage""" + super().setUp() + self.task_3_projectuser_initial_personal_stage = self.task_3.with_user( + self.user_projectuser + ).personal_stage_id.stage_id + + def tearDown(self): + """Personal Stage no other assignees shouldn't be modified + + Personal Stage on other Task assignees shouldn't be modified + by the actions of the user that performs task closing. + """ + super().tearDown() + self.assertEqual( + self.task_3_projectuser_initial_personal_stage, + self.task_3.with_user(self.user_projectuser).personal_stage_id.stage_id, + "Personal Stage on other assignees has been modified", + ) + + def test_personal_stage_not_change(self): + """Personal Stage don't change + + Personal stage don't change if task stage is not on a closing stage. + """ + target_task_stage = self.project_task_stages[1] # In progress stage + old_personal_stage = self.task_3.with_user( + self.user_projectmanager + ).personal_stage_id.stage_id + self.task_3.with_user(self.user_projectmanager).stage_id = target_task_stage.id + new_personal_stage = self.task_3.with_user( + self.user_projectmanager + ).personal_stage_id.stage_id + self.assertEqual(old_personal_stage, new_personal_stage) + + def test_personal_stage_changes_to_one_with_the_same_name(self): + """Personal Stage changes to the same name as Task Stage + + Personal stage change if task stage is on a closing stage and changes + to the one with the same name of the task stage. + """ + target_task_stage = self.project_task_stages[3] # Canceled stage + self.task_3.with_user(self.user_projectmanager).stage_id = target_task_stage.id + new_personal_stage = self.task_3.with_user( + self.user_projectmanager + ).personal_stage_id.stage_id + self.assertEqual(new_personal_stage.name, target_task_stage.name) + + def test_personal_stage_changes_to_first_personal_closing_stage(self): + """Personal Stage changes to the first closing or folded stage + + Personal stage changes to a closing or fold stage + if task stage is on a closing stage + and the name of the personal stage is not found. + """ + personal_target_closing_stage = self.env["project.task.type"].search( + [ + ("user_id", "=", self.user_projectmanager.id), + ("fold", "=", True), + ], + order="fold desc", + limit=1, + ) + target_task_stage = self.project_task_stages[2] # Finished stage + self.task_3.with_user(self.user_projectmanager).stage_id = target_task_stage.id + new_personal_stage = self.task_3.with_user( + self.user_projectmanager + ).personal_stage_id.stage_id + self.assertEqual(new_personal_stage, personal_target_closing_stage)