Odoo 19→20 銷售(sale)訂單節行新增數量與單位

Odoo 19→20 銷售差異 01

結論: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

遷移清單

  1. 檢查自有模組是否已有同名的 section_qty、section_uom_id,避免衝突。
  2. 批次寫入 sale.order.line 時,非節行不要傳這兩個欄位,否則會違反約束。
  3. 自訂 PDF 僅在 section_qty 不等於 1 或單位非預設時顯示節數量。
  4. 前端二開請注意節行已由 SectionLineRecord 接管,修改數量會依比例重算明細。

小結

節行變成帶量綱的分組,報價更順手,升級時記得清理非節行資料。

关于我们

​我们致力于帮助中小企业实现数字化转型,我们的团队由一群充满激情和创新思维的专业人士组成,他们具备丰富的行业经验和技术专长。

扫一扫获取顾问以及手册

登入 發表評論
Odoo 19→20 採購(purchase)訂單行單位欄位更名 uom_id
Odoo 19→20 採購差異 01