我正在尝试扩展在Odoo 10中显示包的视图,因此它还显示了product_id:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='pack_operation_product_ids']/tree/field[@name='package_id']" position="after">
<field name="package_id.product_id"/>
</xpath>
</field>
</record>
所以基本上我希望从product_id
显示相关字段pack_operation_product_id
。
实施此方法的正确方法是什么?
答案 0 :(得分:1)
首先,您必须在继承的python类中包含相关字段。
class StockPicking(models.Model):
_inherit = "stock.picking"
product_id = fields.Many2one('product.product', related='package_id.product_id', string='Product', store=True)
然后在XML中,你可以写如下:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='pack_operation_product_ids']/tree/field[@name='package_id']" position="after">
<field name="product_id"/>
</xpath>
</field>
</record>