Base Line Numbering

Technical module providing line.numbering.mixin, a mixin that
numbers the lines of a record (e.g. the lines of an order) with
consecutive positions (1, 2, 3, … or, with a step of 10, 10, 20, 30,
…), following the lines’ order.
It has no functional effect on its own. It is a building block for
modules that need a stable line reference, shown to users and exchanged
with third parties (e.g. a position on purchase, sale or stock move
lines).
Positions are renumbered automatically when lines are added or removed,
in any state of the record. Consuming modules can opt out for specific
records (e.g. records already sent to a partner).
Table of contents
Several documents exchanged with partners (orders, deliveries, invoices)
refer to their lines by a position number, like 10, 20, 30.
Each module that needs it used to implement its own numbering. This
module provides the numbering once, so that every model numbers its
lines the same way.
This module is meant for developers. Inherit the mixin on the parent
model and declare which lines to number and where to store their
position:
class PurchaseOrder(models.Model):
_name = "purchase.order"
_inherit = ["purchase.order", "line.numbering.mixin"]
_line_numbering_lines_field = "order_line"
_line_numbering_position_field = "position"
_line_numbering_step = 10
- _line_numbering_lines_field: the one2many field holding the lines
to number.
- _line_numbering_position_field: the field of the lines that stores
the position. It is meant to be an integer field; a char field gets
the positions as strings (e.g. when it also stores references coming
from a partner).
- _line_numbering_step: the gap between two consecutive positions
(default: 1).
renumber_lines_positions() numbers the lines of the records
explicitly. create() and write() call it automatically when the
lines change.
The behaviour can be adapted by overriding:
- _line_renumber_needed(): return False to skip the automatic
renumbering for a record (e.g. a locked one). By default, it is
skipped only when the skip_line_auto_renumber context key is set.
- _line_renumber_trigger_fields(): the write() keys that
re-trigger the numbering. Defaults to
[_line_numbering_lines_field]. Override it when
_line_numbering_lines_field is a computed one2many, which never
appears in write() values.
- _line_renumber_get_lines(): the lines to number, in the order they
get their positions. Defaults to the lines of
_line_numbering_lines_field in their model’s order.
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.
This module is maintained by the OCA.
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/server-ux project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.