From d5c9e591a90ae9d449735e42ca8bdcc20435d25a Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Tue, 21 Apr 2026 16:56:42 +0200 Subject: [PATCH] [ADD] project_task_code_by_project --- project_task_code_by_project/README.rst | 96 ++++ project_task_code_by_project/__init__.py | 1 + project_task_code_by_project/__manifest__.py | 18 + .../models/__init__.py | 5 + .../models/project_project.py | 17 + .../models/project_task.py | 21 + project_task_code_by_project/pyproject.toml | 3 + .../readme/CONFIGURE.md | 4 + .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 3 + project_task_code_by_project/readme/USAGE.md | 2 + .../static/description/index.html | 447 ++++++++++++++++++ .../tests/__init__.py | 3 + .../test_project_task_code_by_project.py | 50 ++ .../views/project_view.xml | 13 + 15 files changed, 686 insertions(+) create mode 100644 project_task_code_by_project/README.rst create mode 100644 project_task_code_by_project/__init__.py create mode 100644 project_task_code_by_project/__manifest__.py create mode 100644 project_task_code_by_project/models/__init__.py create mode 100644 project_task_code_by_project/models/project_project.py create mode 100644 project_task_code_by_project/models/project_task.py create mode 100644 project_task_code_by_project/pyproject.toml create mode 100644 project_task_code_by_project/readme/CONFIGURE.md create mode 100644 project_task_code_by_project/readme/CONTRIBUTORS.md create mode 100644 project_task_code_by_project/readme/DESCRIPTION.md create mode 100644 project_task_code_by_project/readme/USAGE.md create mode 100644 project_task_code_by_project/static/description/index.html create mode 100644 project_task_code_by_project/tests/__init__.py create mode 100644 project_task_code_by_project/tests/test_project_task_code_by_project.py create mode 100644 project_task_code_by_project/views/project_view.xml diff --git a/project_task_code_by_project/README.rst b/project_task_code_by_project/README.rst new file mode 100644 index 0000000000..344e3990fd --- /dev/null +++ b/project_task_code_by_project/README.rst @@ -0,0 +1,96 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +==================== +Task Code by Project +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:63c0d6a3809828449e9d4d2727417b402f61962c2b556f95bdea593c1b522f0e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/project_task_code_by_project + :alt: OCA/project +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/project-19-0/project-19-0-project_task_code_by_project + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Extends ``project_task_code`` to let each project use its own task code +sequence. Tasks with no project, or with a project that has no sequence +set, keep using the global sequence. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +1. Create a sequence at Settings > Technical > Sequences & Identifiers > + Sequences (developer mode). +2. Open the project, go to the **Settings** tab and pick it in the + **Task Sequence** field. + +Usage +===== + +New tasks in a project with a sequence get their code from it. Otherwise +the global task sequence is used. + +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 +------- + +* Forgeflow + +Contributors +------------ + +- Aaron Henriquez + +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_code_by_project/__init__.py b/project_task_code_by_project/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/project_task_code_by_project/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/project_task_code_by_project/__manifest__.py b/project_task_code_by_project/__manifest__.py new file mode 100644 index 0000000000..2ac124d553 --- /dev/null +++ b/project_task_code_by_project/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2026 Forgeflow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Task Code by Project", + "version": "19.0.1.0.0", + "category": "Project Management", + "author": "Forgeflow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/project", + "license": "AGPL-3", + "depends": [ + "project_task_code", + ], + "data": [ + "views/project_view.xml", + ], + "installable": True, +} diff --git a/project_task_code_by_project/models/__init__.py b/project_task_code_by_project/models/__init__.py new file mode 100644 index 0000000000..54d64d7722 --- /dev/null +++ b/project_task_code_by_project/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2025 Forgeflow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import project_project +from . import project_task diff --git a/project_task_code_by_project/models/project_project.py b/project_task_code_by_project/models/project_project.py new file mode 100644 index 0000000000..1c2885bd9e --- /dev/null +++ b/project_task_code_by_project/models/project_project.py @@ -0,0 +1,17 @@ +# Copyright 2026 Forgeflow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProjectProject(models.Model): + _inherit = "project.project" + + task_sequence_id = fields.Many2one( + comodel_name="ir.sequence", + string="Task Sequence", + ondelete="set null", + copy=False, + help="Sequence used for task codes in this project. " + "If not set, the global task sequence is used.", + ) diff --git a/project_task_code_by_project/models/project_task.py b/project_task_code_by_project/models/project_task.py new file mode 100644 index 0000000000..e60556d843 --- /dev/null +++ b/project_task_code_by_project/models/project_task.py @@ -0,0 +1,21 @@ +# Copyright 2026 Forgeflow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProjectTask(models.Model): + _inherit = "project.task" + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("code", "/") != "/": + continue + project_id = vals.get("project_id") + if not project_id: + continue + project = self.env["project.project"].browse(project_id) + if project.task_sequence_id: + vals["code"] = project.task_sequence_id.next_by_id() or "/" + return super().create(vals_list) diff --git a/project_task_code_by_project/pyproject.toml b/project_task_code_by_project/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/project_task_code_by_project/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/project_task_code_by_project/readme/CONFIGURE.md b/project_task_code_by_project/readme/CONFIGURE.md new file mode 100644 index 0000000000..17a9253042 --- /dev/null +++ b/project_task_code_by_project/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +1. Create a sequence at Settings \> Technical \> Sequences & Identifiers + \> Sequences (developer mode). +2. Open the project, go to the **Settings** tab and pick it in the + **Task Sequence** field. diff --git a/project_task_code_by_project/readme/CONTRIBUTORS.md b/project_task_code_by_project/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..5eba99218e --- /dev/null +++ b/project_task_code_by_project/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [ForgeFlow](https://www.forgeflow.com): + + > - Aaron Henriquez diff --git a/project_task_code_by_project/readme/DESCRIPTION.md b/project_task_code_by_project/readme/DESCRIPTION.md new file mode 100644 index 0000000000..e7bd8c3d77 --- /dev/null +++ b/project_task_code_by_project/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +Extends `project_task_code` to let each project use its own task code +sequence. Tasks with no project, or with a project that has no sequence +set, keep using the global sequence. diff --git a/project_task_code_by_project/readme/USAGE.md b/project_task_code_by_project/readme/USAGE.md new file mode 100644 index 0000000000..16dcd24178 --- /dev/null +++ b/project_task_code_by_project/readme/USAGE.md @@ -0,0 +1,2 @@ +New tasks in a project with a sequence get their code from it. Otherwise +the global task sequence is used. diff --git a/project_task_code_by_project/static/description/index.html b/project_task_code_by_project/static/description/index.html new file mode 100644 index 0000000000..343ffaf3af --- /dev/null +++ b/project_task_code_by_project/static/description/index.html @@ -0,0 +1,447 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Task Code by Project

+ +

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

+

Extends project_task_code to let each project use its own task code +sequence. Tasks with no project, or with a project that has no sequence +set, keep using the global sequence.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Create a sequence at Settings > Technical > Sequences & Identifiers > +Sequences (developer mode).
  2. +
  3. Open the project, go to the Settings tab and pick it in the +Task Sequence field.
  4. +
+
+
+

Usage

+

New tasks in a project with a sequence get their code from it. Otherwise +the global task sequence is used.

+
+
+

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

+
    +
  • Forgeflow
  • +
+
+
+

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_code_by_project/tests/__init__.py b/project_task_code_by_project/tests/__init__.py new file mode 100644 index 0000000000..8c6d582f55 --- /dev/null +++ b/project_task_code_by_project/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_project_task_code_by_project diff --git a/project_task_code_by_project/tests/test_project_task_code_by_project.py b/project_task_code_by_project/tests/test_project_task_code_by_project.py new file mode 100644 index 0000000000..6fbd4e2c6c --- /dev/null +++ b/project_task_code_by_project/tests/test_project_task_code_by_project.py @@ -0,0 +1,50 @@ +# Copyright 2026 Forgeflow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.base.tests.common import BaseCommon + + +class TestProjectTaskCodeByProject(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.project_task_model = cls.env["project.task"] + cls.global_sequence = cls.env.ref("project_task_code.sequence_task") + cls.project_with_seq = cls.env["project.project"].create( + {"name": "Project With Sequence"} + ) + cls.project_without_seq = cls.env["project.project"].create( + {"name": "Project Without Sequence"} + ) + cls.project_sequence = cls.env["ir.sequence"].create( + { + "name": "Test Project Task Sequence", + "code": "project.task.test", + "padding": 4, + "prefix": "PWS-", + } + ) + cls.project_with_seq.task_sequence_id = cls.project_sequence + + def test_task_with_project_sequence_flow(self): + project_next = self.project_sequence.number_next_actual + project_expected = self.project_sequence.get_next_char(project_next) + global_next_before = self.global_sequence.number_next_actual + task = self.project_task_model.create( + { + "name": "Task with project sequence", + "project_id": self.project_with_seq.id, + } + ) + self.assertEqual(task.code, project_expected) + self.assertTrue(task.code.startswith("PWS-")) + self.assertRegex(task.display_name, f"\\[{project_expected}\\]") + self.assertEqual(self.global_sequence.number_next_actual, global_next_before) + + def test_task_fallback_to_global_sequence_flow(self): + global_next = self.global_sequence.number_next_actual + global_expected = self.global_sequence.get_next_char(global_next) + task_no_project = self.project_task_model.create( + {"name": "Task without project"} + ) + self.assertEqual(task_no_project.code, global_expected) diff --git a/project_task_code_by_project/views/project_view.xml b/project_task_code_by_project/views/project_view.xml new file mode 100644 index 0000000000..658706f3a3 --- /dev/null +++ b/project_task_code_by_project/views/project_view.xml @@ -0,0 +1,13 @@ + + + + project.project.form.task.sequence + project.project + + + + + + + +