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 安装后执行。 - 回归跟踪库存产品计算与看板。
小结
模块归属下沉加方法改名,字段名稳定,重点是覆盖点和依赖声明要跟着调。
