I have a scenario where a field has to be displayed based on value of the selection field.
class mro_order(osv.osv):
_inherit="mro.order"
_columns={
'released_part':fields.one2many('mro.released', 'released_id', 'Released parts',),
'rel_id':fields.many2one('mro.released', 'Parts'),
'parts_id1': fields.many2one('product.product', 'Parts', required=True, domain = [('maintain_ok','=',True)],),
}
class mro_order_parts_line(osv.osv):
_inherit="mro.order.parts.line"
_columns={
'sts': fields.selection([
('new', 'New'),
('release', 'released'),
], 'State', default='new', readonly= False, select=True),
}
def onchange_sts(self, cr, uid, ids, sts):
value = {}
if sts == 'release':
value['parts_id'] = fields.many2one('mro.released','Parts')
return value
class mro_released(osv.Model):
_name="mro.released"
_columns={
'name': fields.char('Description', size=64),
'parts_id': fields.char('Parts'),
'parts_qty': fields.float('Quantity'),
'parts_uom': fields.many2one('product.uom','Unit of Measure'),
'released_id': fields.many2one('mro.order', 'Maintenance Order'),
'state': fields.selection([
('scrap', 'Scrap'),
('reusable', 'Re-usable'),
], 'State', readonly= False, select=True, required=True),
}
This is my xml file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="released_parts_id">
<field name="name">mro.order.form</field>
<field name="model">mro.order</field>
<field name="inherit_id" ref="mro.mro_order_form_view"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/group/field/tree/field[@name='parts_id']" position="before">
<field name="sts" onchange="onchange_sts(sts)"/>
</xpath>
<xpath expr="//form/sheet/notebook/page/group[@string='Planned Parts']" position="after">
<group string="Released Parts">
<field name="released_part" nolabel="1">
<tree string="Released Parts" editable="bottom">
<field name="parts_id" />
<field name="parts_qty"/>
<field name="parts_uom" />
<field name="name"/>
</tree>
</field>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
Based on the value of selection field, I want to change the relation of a many2one field or based on the value of selection field replace another many2one field named 'A' with different relation to replace the other many2one field named 'B' with different relation in the tree view of xml.
Kindly anyone has any idea on this?