diff --git a/project_sequence_type/README.rst b/project_sequence_type/README.rst new file mode 100644 index 0000000000..37d056b87b --- /dev/null +++ b/project_sequence_type/README.rst @@ -0,0 +1,108 @@ +======================== +Project Sequence by Type +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ca9cf96f614e54fae021c9b58905327d471e220bee5242c341caf8084d9c29a2 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/18.0/project_sequence_type + :alt: OCA/project +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/project-18-0/project-18-0-project_sequence_type + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module lets each project type define its own sequence, so projects +get a different numbering depending on their type. + +It is a glue module between ``project_sequence`` and ``project_type`` +and is installed automatically when both are present. + +Projects whose type has no sequence (or projects without a type) keep +using the default project sequence provided by ``project_sequence``. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Settings > Technical > Sequences & Identifiers > Sequences* + and create one sequence per project type you want to number + separately (set its prefix, padding, etc. as usual). +2. Go to *Project > Configuration > Project Types*, open a type and set + its *Project Sequence* to the sequence created above. +3. Create a project of that type: its sequence code is taken from the + type's sequence. Types without a sequence keep using the default + project sequence. + +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 +------- + +* Ledo + +Contributors +------------ + +- Ledo + +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. + +.. |maintainer-dnplkndll| image:: https://github.com/dnplkndll.png?size=40px + :target: https://github.com/dnplkndll + :alt: dnplkndll + +Current `maintainer `__: + +|maintainer-dnplkndll| + +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_sequence_type/__init__.py b/project_sequence_type/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/project_sequence_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/project_sequence_type/__manifest__.py b/project_sequence_type/__manifest__.py new file mode 100644 index 0000000000..bc82b98cfe --- /dev/null +++ b/project_sequence_type/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2026 Ledo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Project Sequence by Type", + "summary": "Give projects a different sequence depending on their type", + "version": "18.0.1.0.0", + "category": "Services/Project", + "development_status": "Alpha", + "website": "https://github.com/OCA/project", + "author": "Ledo, Odoo Community Association (OCA)", + "maintainers": ["dnplkndll"], + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": ["project_sequence", "project_type"], + "data": [ + "views/project_type_views.xml", + ], +} diff --git a/project_sequence_type/models/__init__.py b/project_sequence_type/models/__init__.py new file mode 100644 index 0000000000..630e8ba76a --- /dev/null +++ b/project_sequence_type/models/__init__.py @@ -0,0 +1,2 @@ +from . import project_type +from . import project_project diff --git a/project_sequence_type/models/project_project.py b/project_sequence_type/models/project_project.py new file mode 100644 index 0000000000..c73af4c390 --- /dev/null +++ b/project_sequence_type/models/project_project.py @@ -0,0 +1,25 @@ +# Copyright 2026 Ledo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProjectProject(models.Model): + _inherit = "project.project" + + @api.model_create_multi + def create(self, vals_list): + """Use the project type's own sequence when it defines one. + + ``project_sequence`` fills ``sequence_code`` from the global + ``project.sequence`` when the key is absent. We pre-fill it from the + type's sequence so that branch is skipped; types without a sequence + (or projects without a type) keep falling back to the default. + """ + for vals in vals_list: + if "sequence_code" in vals or not vals.get("type_id"): + continue + sequence = self.env["project.type"].browse(vals["type_id"]).sequence_id + if sequence: + vals["sequence_code"] = sequence.next_by_id() + return super().create(vals_list) diff --git a/project_sequence_type/models/project_type.py b/project_sequence_type/models/project_type.py new file mode 100644 index 0000000000..57575292d2 --- /dev/null +++ b/project_sequence_type/models/project_type.py @@ -0,0 +1,18 @@ +# Copyright 2026 Ledo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProjectType(models.Model): + _inherit = "project.type" + + sequence_id = fields.Many2one( + comodel_name="ir.sequence", + string="Project Sequence", + copy=False, + help=( + "Projects of this type take their sequence code from this sequence. " + "When left empty, the default project sequence is used." + ), + ) diff --git a/project_sequence_type/pyproject.toml b/project_sequence_type/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/project_sequence_type/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/project_sequence_type/readme/CONTRIBUTORS.md b/project_sequence_type/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..15e495aff6 --- /dev/null +++ b/project_sequence_type/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Ledo diff --git a/project_sequence_type/readme/DESCRIPTION.md b/project_sequence_type/readme/DESCRIPTION.md new file mode 100644 index 0000000000..80ef2167b1 --- /dev/null +++ b/project_sequence_type/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module lets each project type define its own sequence, so projects +get a different numbering depending on their type. + +It is a glue module between `project_sequence` and `project_type` and is +installed automatically when both are present. + +Projects whose type has no sequence (or projects without a type) keep +using the default project sequence provided by `project_sequence`. diff --git a/project_sequence_type/readme/USAGE.md b/project_sequence_type/readme/USAGE.md new file mode 100644 index 0000000000..16786ca5b9 --- /dev/null +++ b/project_sequence_type/readme/USAGE.md @@ -0,0 +1,8 @@ +1. Go to *Settings \> Technical \> Sequences & Identifiers \> + Sequences* and create one sequence per project type you want to + number separately (set its prefix, padding, etc. as usual). +2. Go to *Project \> Configuration \> Project Types*, open a type and + set its *Project Sequence* to the sequence created above. +3. Create a project of that type: its sequence code is taken from the + type's sequence. Types without a sequence keep using the default + project sequence. diff --git a/project_sequence_type/static/description/index.html b/project_sequence_type/static/description/index.html new file mode 100644 index 0000000000..24a26518a0 --- /dev/null +++ b/project_sequence_type/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +Project Sequence by Type + + + +
+

Project Sequence by Type

+ + +

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

+

This module lets each project type define its own sequence, so projects +get a different numbering depending on their type.

+

It is a glue module between project_sequence and project_type +and is installed automatically when both are present.

+

Projects whose type has no sequence (or projects without a type) keep +using the default project sequence provided by project_sequence.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Settings > Technical > Sequences & Identifiers > Sequences +and create one sequence per project type you want to number +separately (set its prefix, padding, etc. as usual).
  2. +
  3. Go to Project > Configuration > Project Types, open a type and set +its Project Sequence to the sequence created above.
  4. +
  5. Create a project of that type: its sequence code is taken from the +type’s sequence. Types without a sequence keep using the default +project sequence.
  6. +
+
+
+

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

+
    +
  • Ledo
  • +
+
+
+

Contributors

+
    +
  • Ledo
  • +
+
+
+

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.

+

Current maintainer:

+

dnplkndll

+

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_sequence_type/tests/__init__.py b/project_sequence_type/tests/__init__.py new file mode 100644 index 0000000000..6590f2e94e --- /dev/null +++ b/project_sequence_type/tests/__init__.py @@ -0,0 +1 @@ +from . import test_project_sequence_type diff --git a/project_sequence_type/tests/test_project_sequence_type.py b/project_sequence_type/tests/test_project_sequence_type.py new file mode 100644 index 0000000000..010153a89f --- /dev/null +++ b/project_sequence_type/tests/test_project_sequence_type.py @@ -0,0 +1,60 @@ +# Copyright 2026 Ledo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestProjectSequenceType(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Project = cls.env["project.project"] + cls.consulting_seq = cls.env["ir.sequence"].create( + { + "name": "Consulting Projects", + "code": "project.sequence.test.consulting", + "prefix": "CONS-", + "padding": 4, + } + ) + cls.consulting = cls.env["project.type"].create( + {"name": "Consulting", "sequence_id": cls.consulting_seq.id} + ) + cls.internal = cls.env["project.type"].create({"name": "Internal"}) + + def test_type_with_sequence_uses_it(self): + """A project takes its code from its type's sequence.""" + project = self.Project.create( + {"name": "Acme audit", "type_id": self.consulting.id} + ) + self.assertEqual(project.sequence_code, "CONS-0001") + # The type sequence keeps counting for that type. + project2 = self.Project.create( + {"name": "Beta audit", "type_id": self.consulting.id} + ) + self.assertEqual(project2.sequence_code, "CONS-0002") + + def test_type_without_sequence_uses_default(self): + """A type that defines no sequence falls back to the global one.""" + project = self.Project.create( + {"name": "Housekeeping", "type_id": self.internal.id} + ) + self.assertTrue(project.sequence_code) + self.assertFalse(project.sequence_code.startswith("CONS-")) + + def test_no_type_uses_default(self): + """A project with no type keeps the default project sequence.""" + project = self.Project.create({"name": "Misc"}) + self.assertTrue(project.sequence_code) + self.assertFalse(project.sequence_code.startswith("CONS-")) + + def test_explicit_sequence_code_wins(self): + """An explicit sequence_code is never overridden by the type sequence.""" + project = self.Project.create( + { + "name": "Manual", + "type_id": self.consulting.id, + "sequence_code": "MANUAL-1", + } + ) + self.assertEqual(project.sequence_code, "MANUAL-1") diff --git a/project_sequence_type/views/project_type_views.xml b/project_sequence_type/views/project_type_views.xml new file mode 100644 index 0000000000..9fa9fa795a --- /dev/null +++ b/project_sequence_type/views/project_type_views.xml @@ -0,0 +1,14 @@ + + + + + project.type + + + + + + + +