它可以使用相关领域。首先您需要继承销售订单模型并为产品品牌id添加相关字段例如:
from osv import osv, fields
class sale_order_line(osv.osv):
_inherit = 'sale.order.line'
_columns = {
'brand_id': fields.related('product_id','product_brand_id',string='Brand',type='many2one',relation='product.brand')
}
sale_order_line()
然后需要继承销售订单视图。销售订单行树和表单视图在销售订单视图中指定。所以使用 xpath 继承销售订单表单视图。例如:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_inherited_brand">
<field name="name">sale.order.brand</field>
<field name="type">form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="after">
<field name='brand_id'/>
</xpath>
</field>
</record>
</data>
</openerp>