Odoo 19→20 產品(product)is_storable 欄位下沉 stock→product

Odoo 19→20 產品差異 01

Odoo 20 把 is_storable 從 stock 模組移到 product 模組,計算方法改名為 _compute_is_storable。欄位名不變,但歸屬和方法名變了,覆寫點要改。

場景

二次開發常在庫存模組繼承 product.template,覆寫追蹤庫存的計算,或用 is_storable 篩選建立看板。歸屬或方法名一變,升級後就覆寫不到。

Odoo 19 的寫法

19 欄位和計算方法都在 stock 模組,compute 指向 compute_is_storable,方法無底線前綴。

# Odoo 19 · stock/models/product.py
    is_storable = fields.Boolean(
        'Track Inventory', store=True, compute='compute_is_storable', readonly=False,
        default=False, precompute=True, tracking=True, help='A storable product is a product for which you manage stock.')

    @api.depends('type')
    def compute_is_storable(self):
        self.filtered(lambda t: t.type != 'consu' and t.is_storable).is_storable = False

Odoo 20 的寫法

20 欄位搬到 product 模組,方法改為 _compute_is_storable,只依賴 product 也能直接用。

# Odoo 20 · product/models/product_template.py
    is_storable = fields.Boolean(
        'Track Inventory', store=True, compute='_compute_is_storable', readonly=False,
        default=False, precompute=True, tracking=True,
        help='A storable product is a product for which you manage stock.')

    @api.depends('type')
    def _compute_is_storable(self):
        self.filtered(lambda t: t.type != 'consu' and t.is_storable).is_storable = False

遷移清單

  1. 覆寫 compute_is_storable 的繼承改成 _compute_is_storable。
  2. 只依賴 product 的模組可直接用 is_storable,無需再依賴 stock。
  3. 搜尋域、檢視中的 is_storable 欄位名不變,無需修改。
  4. 依 is_storable 篩選的遷移腳本放到 stock 安裝後執行。
  5. 回歸追蹤庫存產品的計算與看板。

小結

模組歸屬下沉加方法改名,欄位名穩定,重點是覆寫點和依賴宣告要跟著調整。

关于我们

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

扫一扫获取顾问以及手册

登入 發表評論
Odoo 19→20 會計(account)付款狀態機重構:in_process 改為 reconciled
Odoo 19→20 會計差異 01