Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions sale_order_line_section/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.. 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 adds a stored Section field on sale order lines.

In standard Odoo, the relation between a line and its section is only
implicit: a line belongs to the nearest previous section according to
the order sequence. This is inconvenient for domains, grouping,
reporting, or custom business logic because there is no direct field to
use.

With this module, each non-section sale order line is linked to its
nearest previous section line.

Typical use cases include:

- grouping sale order lines by section in tree views, exports, or
reports;
- filtering all lines that belong to a given section without recomputing
the relation from the sequence;

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_order_line_section%0Aversion:%2019.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.

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 <https://github.com/OCA/sale-workflow/tree/19.0/sale_order_line_section>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions sale_order_line_section/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
22 changes: 22 additions & 0 deletions sale_order_line_section/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
41 changes: 41 additions & 0 deletions sale_order_line_section/hooks.py
Original file line number Diff line number Diff line change
@@ -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
"""
)
37 changes: 37 additions & 0 deletions sale_order_line_section/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -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"
36 changes: 36 additions & 0 deletions sale_order_line_section/i18n/sale_order_line_section.pot
Original file line number Diff line number Diff line change
@@ -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 ""
1 change: 1 addition & 0 deletions sale_order_line_section/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order_line
44 changes: 44 additions & 0 deletions sale_order_line_section/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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"

# Store the section link so domains and section-based analysis can use it
# directly without reconstructing the relation from line sequence. Since
# the field is expected to be used in searches and filters, indexing it is
# justified.
section_id = fields.Many2one(
comodel_name="sale.order.line",
string="Section",
compute="_compute_section_id",
compute_sudo=True,
store=True,
index=True,
Comment thread
simahawk marked this conversation as resolved.
)

@api.depends(
"order_id",
"display_type",
"order_id.order_line",
"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
3 changes: 3 additions & 0 deletions sale_order_line_section/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions sale_order_line_section/readme/CONTRIBUTOR.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Telmo Santos <telmo.santos@camptocamp.com>
15 changes: 15 additions & 0 deletions sale_order_line_section/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This module adds a stored Section field on sale order lines.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


In standard Odoo, the relation between a line and its section is only implicit:
a line belongs to the nearest previous section according to the order sequence.
This is inconvenient for domains, grouping, reporting, or custom business logic
because there is no direct field to use.

With this module, each non-section sale order line is linked to its nearest
previous section line.

Typical use cases include:

- grouping sale order lines by section in tree views, exports, or reports;
- filtering all lines that belong to a given section without recomputing the
relation from the sequence;
Loading
Loading