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