A try to modified purchase_order_line but onchange_product and field related are wrong .
Here my new class product_template :
class product_template(osv.osv): _name = 'product.template' _inherit = 'product.template'
_columns = { 'my_field_id': fields.many2one('product.uom','My_Field'),
the new .xml for product_template and purchase_order_line views :
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.common.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field eval="25" name="priority"/>
<field name="arch" type="xml">
<field name="uom_id" position="after">
<field name="my_field_id"/>
</field>
</field>
</record>
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase_order_form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field eval="90" name="priority"/>
<field name="arch" type="xml">
<xpath expr="/form[@string='Purchase Order']/sheet/notebook/page[@string='Products']/field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='price_unit']" position="before">
<field name="my_field_po" string="My_Field"/>
</xpath>
</field>
</record>
</xpath>
</field>
And class purchase_order_line for which I ask little help
class purchase_order_line(osv.osv): _name = 'purchase.order.line' _inherit = 'purchase.order.line'
def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, state='draft', context=None): res = super(purchase_order_line, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned, name=name, price_unit=price_unit, state=state, context=context) if 'value' in res: my_field_po = self.pool.get('product.product').browse(cr, uid, product_id, context=context).unitestock_po_id res['value'].update({'my_field_po': my_field_po and my_field_po.id or False}) return res _columns = { 'my_field_po': fields.related('product_id','my_field_id',type='many2one',relation='product.template',string='My_Field',store=True), }
Your onchange_product_id is executed?
I think no, the field in the p.o.line is always "white" when I choose a product . This is my question.