I am trying to extend the view which displays packages in Odoo 10 so it display also the 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>
So basically I am looking to display related field product_id
from pack_operation_product_id
.
Which is the right approach to implement this?
First you must include the related field in your inherited python class.
class StockPicking(models.Model):
_inherit = "stock.picking"
product_id = fields.Many2one('product.product', related='package_id.product_id', string='Product', store=True)
Then in XML you can write like the following:
<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>