结论:Odoo 20 给销售订单的节行加了自己的数量与单位,节不再只是纯文本标题。改节数量会按比例缩放整节明细。
场景
服务报价常按阶段分节,如“实施 3 套”。19 只能在每行明细填数量;20 可直接在节上录数量和单位,一次调整整节。
Odoo 19 的写法
19 的节相关字段只有 parent_id、collapse_prices、collapse_composition,没有数量概念。
# Odoo 19 · sale/models/sale_order_line.py
# Section-related fields
parent_id = fields.Many2one(
string="Parent Section Line",
comodel_name='sale.order.line',
compute='_compute_parent_id',
) # The section or subsection this line belongs to.
collapse_prices = fields.Boolean(
string="Collapse Prices",
copy=True,
default=False,
) # Whether this section's lines' prices will be hidden in reports and in the portal.
Odoo 20 的写法
20 新增 section_qty 与 section_uom_id(默认 1 与 Units,可编辑存储),并加 _section_fields_null 约束,非节行不许带这两个值。
# Odoo 20 · sale/models/sale_order_line.py
section_qty = fields.Float(
string="Section Quantity",
digits="Product Unit",
compute="_compute_section_qty",
precompute=True,
store=True,
readonly=False,
) # The total quantity of the section
section_uom_id = fields.Many2one(
comodel_name="uom.uom",
string="Section Unit of Measure",
compute="_compute_section_uom_id",
precompute=True,
store=True,
readonly=False,
) # The unit of measure of the section
迁移清单
- 检查自有模块是否已有同名 section_qty、section_uom_id,避免冲突。
- 批量写 sale.order.line 时非节行不要传这两个字段,否则违反约束。
- 自定义 PDF 仅在 section_qty 不等于 1 或单位非默认时显示节数量。
- 前端二开注意节行已由 SectionLineRecord 接管,改数量会按比例重算明细。
小结
节行变成带量纲的分组,报价更顺手,升级时记得清洗非节行数据。
