Odoo中product.product使用的list_price字段声明位置查询
问题背景
你贴出的是Odoo中product.product模型计算lst_price的核心逻辑,其中用到的list_price确实没有直接在product.product中声明,具体来源如下:
字段声明位置
list_price是定义在**product.template(商品模板模型)**中的字段,对应代码位于Odoo官方product模块的models/product_template.py文件内,典型的字段声明代码如下:
list_price = fields.Float( 'Sales Price', default=1.0, digits='Product Price', help="Price at which the product is sold to customers." )
可在product.product中直接访问的原因
Odoo的product.product(商品变体模型)对product.template使用了代理继承机制,你可以在product.product的模型定义开头看到如下配置:
class ProductProduct(models.Model): _name = 'product.product' _inherits = {'product.template': 'product_tmpl_id'} # 其余模型逻辑省略
代理继承的特性是子模型可以无需重复声明,直接访问父模型的所有字段,你在代码中操作product.list_price时,本质是读写该变体关联的product.template记录的list_price值。
内容的提问来源于stack exchange,提问作者wahyu eko hadi saputro
相关产品推荐
相关产品推荐

