Odoo中model中使用_inherit / _inherits属性简介
以odoo12环境为例,生产厂家模型为例进行解释说明。
1.正常使用 “_inherit” 是用于对模型进行继承修改,常见于如下定义:
class AccountMove(models.Model):
_inherit = 'account.move'
stock_move_id = fields.Many2one('stock.move', string='Stock Move')
其中使用 “_inherit” 属性表示对原有模型的继承修改,这其中不包含 “_name” 属性。
查看数据库字段会发现对原有表增加新继承新定义的字段。
2.同时使用 “_inherit” , “_name” 或者 同时使用 “_inherits” , “_name” ,
2.1 先看 “_inherit” , “_name” 同时存在情况,如下边代码定义:
class StockManufacturer(models.Model):
_name = ‘stock.manufacturer’
_description = ‘Stock Manufacturer’
_order = ‘id asc’
# 名称
name = fields.Char('Manufacturer Name', required=True, index=True)
# 编码
number = fields.Char('Manufacturer Number', index=True, copy=False)
# 类型: 生产厂家、代理商
manufacturer_type = fields.S