diff --git a/sale_order_line_section/README.rst b/sale_order_line_section/README.rst new file mode 100644 index 00000000000..966711a166a --- /dev/null +++ b/sale_order_line_section/README.rst @@ -0,0 +1,82 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================= +sale_order_line_section +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4a6be1703d2fb286f032a0757e7a68a54f9f37f8be3e7f1aab9c569c9284e115 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/19.0/sale_order_line_section + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-19-0/sale-workflow-19-0-sale_order_line_section + :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/sale-workflow&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows organizing and managing sale order lines by section. + +It computes a Section field on each sale order line so that non-section +lines are linked to the nearest previous section line in the order +sequence. + +This makes it easier to group, filter, and analyze sale order lines by +section. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Camptocamp + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_line_section/__init__.py b/sale_order_line_section/__init__.py new file mode 100644 index 00000000000..6d58305f5dd --- /dev/null +++ b/sale_order_line_section/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import pre_init_hook diff --git a/sale_order_line_section/__manifest__.py b/sale_order_line_section/__manifest__.py new file mode 100644 index 00000000000..ff6781fb0f3 --- /dev/null +++ b/sale_order_line_section/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +{ + "name": "sale_order_line_section", + "summary": "Section on sale order line", + "version": "19.0.1.0.0", + "category": "Sale", + "website": "https://github.com/OCA/sale-workflow", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "sale", + ], + "data": [ + "views/sale_order_view.xml", + ], + "pre_init_hook": "pre_init_hook", +} diff --git a/sale_order_line_section/hooks.py b/sale_order_line_section/hooks.py new file mode 100644 index 00000000000..da1dd4b8595 --- /dev/null +++ b/sale_order_line_section/hooks.py @@ -0,0 +1,41 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo.tools.sql import column_exists, create_column + +_logger = logging.getLogger(__name__) + + +def pre_init_hook(env): + """Initialize stored value for section_id before module installation.""" + cr = env.cr + if column_exists(cr, "sale_order_line", "section_id"): + return + + _logger.info("Create and initialize sale_order_line.section_id") + create_column(cr, "sale_order_line", "section_id", "INTEGER") + cr.execute( + """ + WITH ordered_lines AS ( + SELECT + sol.id, + sol.display_type, + MAX(CASE WHEN sol.display_type = 'line_section' THEN sol.id END) + OVER ( + PARTITION BY sol.order_id + ORDER BY sol.sequence, sol.id + ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING + ) AS previous_section_id + FROM sale_order_line sol + ) + UPDATE sale_order_line sol + SET section_id = CASE + WHEN ol.display_type = 'line_section' THEN NULL + ELSE ol.previous_section_id + END + FROM ordered_lines ol + WHERE sol.id = ol.id + """ + ) diff --git a/sale_order_line_section/i18n/fr.po b/sale_order_line_section/i18n/fr.po new file mode 100644 index 00000000000..0692b024aeb --- /dev/null +++ b/sale_order_line_section/i18n/fr.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_line_section +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-08 11:48+0000\n" +"PO-Revision-Date: 2026-04-08 11:48+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: sale_order_line_section +#: model:ir.model.fields,field_description:sale_order_line_section.field_sale_order_line__display_name +msgid "Display Name" +msgstr "Nom Affiche" + +#. module: sale_order_line_section +#: model:ir.model.fields,field_description:sale_order_line_section.field_sale_order_line__id +msgid "ID" +msgstr "ID" + +#. module: sale_order_line_section +#: model:ir.model,name:sale_order_line_section.model_sale_order_line +msgid "Sales Order Line" +msgstr "Ligne Commande" + +#. module: sale_order_line_section +#: model:ir.model.fields,field_description:sale_order_line_section.field_sale_order_line__section_id +msgid "Section" +msgstr "Section" diff --git a/sale_order_line_section/i18n/sale_order_line_section.pot b/sale_order_line_section/i18n/sale_order_line_section.pot new file mode 100644 index 00000000000..24bf250b852 --- /dev/null +++ b/sale_order_line_section/i18n/sale_order_line_section.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_line_section +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-08 11:48+0000\n" +"PO-Revision-Date: 2026-04-08 11:48+0000\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: sale_order_line_section +#: model:ir.model.fields,field_description:sale_order_line_section.field_sale_order_line__display_name +msgid "Display Name" +msgstr "" + +#. module: sale_order_line_section +#: model:ir.model.fields,field_description:sale_order_line_section.field_sale_order_line__id +msgid "ID" +msgstr "" + +#. module: sale_order_line_section +#: model:ir.model,name:sale_order_line_section.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_order_line_section +#: model:ir.model.fields,field_description:sale_order_line_section.field_sale_order_line__section_id +msgid "Section" +msgstr "" diff --git a/sale_order_line_section/models/__init__.py b/sale_order_line_section/models/__init__.py new file mode 100644 index 00000000000..8eb9d1d4046 --- /dev/null +++ b/sale_order_line_section/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order_line diff --git a/sale_order_line_section/models/sale_order_line.py b/sale_order_line_section/models/sale_order_line.py new file mode 100644 index 00000000000..093cda71b3f --- /dev/null +++ b/sale_order_line_section/models/sale_order_line.py @@ -0,0 +1,42 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + section_id = fields.Many2one( + comodel_name="sale.order.line", + string="Section", + compute="_compute_section_id", + compute_sudo=True, + precompute=True, + store=True, + index=True, + ) + + @api.depends( + "order_id.order_line.sequence", "order_id.order_line.display_type", "sequence" + ) + def _compute_section_id(self): + for line in self: + order = line.order_id + if not order or line.display_type == "line_section": + line.section_id = False + continue + + current_section = False + for order_line in order.order_line.sorted("sequence"): + if order_line == line: + break + if order_line.display_type == "line_section": + current_section = order_line + line.section_id = current_section + + @api.model_create_multi + def create(self, vals_list): + lines = super().create(vals_list) + lines.mapped("order_id.order_line")._compute_section_id() + return lines diff --git a/sale_order_line_section/pyproject.toml b/sale_order_line_section/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_order_line_section/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_order_line_section/readme/CONTRIBUTOR.rst b/sale_order_line_section/readme/CONTRIBUTOR.rst new file mode 100644 index 00000000000..8ed3aebaca0 --- /dev/null +++ b/sale_order_line_section/readme/CONTRIBUTOR.rst @@ -0,0 +1 @@ +* Telmo Santos diff --git a/sale_order_line_section/readme/DESCRIPTION.md b/sale_order_line_section/readme/DESCRIPTION.md new file mode 100644 index 00000000000..2e8618cdf52 --- /dev/null +++ b/sale_order_line_section/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This module allows organizing and managing sale order lines by section. + +It computes a Section field on each sale order line so that non-section lines +are linked to the nearest previous section line in the order sequence. + +This makes it easier to group, filter, and analyze sale order lines by section. diff --git a/sale_order_line_section/static/description/index.html b/sale_order_line_section/static/description/index.html new file mode 100644 index 00000000000..9a46fc37b96 --- /dev/null +++ b/sale_order_line_section/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

sale_order_line_section

+ +

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

+

This module allows organizing and managing sale order lines by section.

+

It computes a Section field on each sale order line so that non-section +lines are linked to the nearest previous section line in the order +sequence.

+

This makes it easier to group, filter, and analyze sale order lines by +section.

+

Table of contents

+ +
+

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

+
    +
  • Camptocamp
  • +
+
+
+

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

+

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

+
+
+
+
+ + diff --git a/sale_order_line_section/tests/__init__.py b/sale_order_line_section/tests/__init__.py new file mode 100644 index 00000000000..ade0fbc37db --- /dev/null +++ b/sale_order_line_section/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_sale_order_line_section diff --git a/sale_order_line_section/tests/test_sale_order_line_section.py b/sale_order_line_section/tests/test_sale_order_line_section.py new file mode 100644 index 00000000000..65ee59e79ba --- /dev/null +++ b/sale_order_line_section/tests/test_sale_order_line_section.py @@ -0,0 +1,101 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestSaleOrderLineSection(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Section Partner"}) + cls.product = cls.env["product.product"].create( + { + "name": "Section Product", + "type": "service", + } + ) + + def _create_order(self): + return self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + {"name": "S1", "display_type": "line_section", "sequence": 10}, + ), + ( + 0, + 0, + { + "name": "L1", + "product_id": self.product.id, + "product_uom_qty": 1.0, + "product_uom_id": self.product.uom_id.id, + "price_unit": 100.0, + "sequence": 20, + }, + ), + ( + 0, + 0, + { + "name": "L2", + "product_id": self.product.id, + "product_uom_qty": 1.0, + "product_uom_id": self.product.uom_id.id, + "price_unit": 100.0, + "sequence": 30, + }, + ), + ( + 0, + 0, + {"name": "S2", "display_type": "line_section", "sequence": 40}, + ), + ( + 0, + 0, + { + "name": "L3", + "product_id": self.product.id, + "product_uom_qty": 1.0, + "product_uom_id": self.product.uom_id.id, + "price_unit": 100.0, + "sequence": 50, + }, + ), + ], + } + ) + + def test_section_id_computed_from_previous_section(self): + order = self._create_order() + s1 = order.order_line.filtered(lambda line: line.name == "S1") + s2 = order.order_line.filtered(lambda line: line.name == "S2") + l1 = order.order_line.filtered(lambda line: line.name == "L1") + l2 = order.order_line.filtered(lambda line: line.name == "L2") + l3 = order.order_line.filtered(lambda line: line.name == "L3") + + self.assertFalse(s1.section_id) + self.assertFalse(s2.section_id) + self.assertEqual(l1.section_id, s1) + self.assertEqual(l2.section_id, s1) + self.assertEqual(l3.section_id, s2) + + def test_section_id_recomputed_when_section_sequence_changes(self): + order = self._create_order() + s1 = order.order_line.filtered(lambda line: line.name == "S1") + s2 = order.order_line.filtered(lambda line: line.name == "S2") + l1 = order.order_line.filtered(lambda line: line.name == "L1") + l2 = order.order_line.filtered(lambda line: line.name == "L2") + l3 = order.order_line.filtered(lambda line: line.name == "L3") + + s2.write({"sequence": 25}) + order.order_line._compute_section_id() + + self.assertEqual(l1.section_id, s1) + self.assertEqual(l2.section_id, s2) + self.assertEqual(l3.section_id, s2) diff --git a/sale_order_line_section/views/sale_order_view.xml b/sale_order_line_section/views/sale_order_view.xml new file mode 100644 index 00000000000..147e69bebe3 --- /dev/null +++ b/sale_order_line_section/views/sale_order_view.xml @@ -0,0 +1,15 @@ + + + + sale.order + + + + + + + +