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 = FalseOdoo 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遷移清單
- 覆寫
compute_is_storable的繼承改成_compute_is_storable。 - 只依賴 product 的模組可直接用
is_storable,無需再依賴 stock。 - 搜尋域、檢視中的
is_storable欄位名不變,無需修改。 - 依
is_storable篩選的遷移腳本放到 stock 安裝後執行。 - 回歸追蹤庫存產品的計算與看板。
小結
模組歸屬下沉加方法改名,欄位名穩定,重點是覆寫點和依賴宣告要跟著調整。
