I have my custom class :
class my_class(osv.osv):
_name = 'my.class'
_columns = {
'name': fields.char('name', size=50),
'my_field': fields.many2one('mrp.bom', 'my fields', domain=[('bom_id','=',False)], required=True),
'my_lines': fields.one2many('my.class', 'my_id', 'My Lines'),
'my_id': fields.many2one('my.class', 'Parent id', ondelete='cascade', select=True),
'field1': fields.float('My fields 1', digits=(10,0)),
'field2': fields.float('My fields 2', digits=(10,0)),
}
my_class()
I create an onchange method to fil the result of the query (bom lines) in columns :
cr.execute ("select product_id as produit, product_qty as qty from mrp_bom where bom_id=(select id from class where product_id =%s limit 1)" %(my_field))
The onchange method :
def onchange_my_field(self, cr, uid, ids, my_field, field1, field2, context=None):
if context is None:
context = {}
context['lang'] = self.pool.get('res.users').browse(cr,uid,uid).context_lang
bom = {}
vals = {}
val = {}
if my_field:
cr.execute ("select product_id as produit, product_qty as qty from mrp_bom where bom_id=(select id from mrp_bom where product_id=%s limit 1)" %(my_field))
bom = cr.dictfetchall()
for val in bom:
vals = {
'field1': val['produit'],
'field2': val['qty'],
}
return {'value': vals}
In my code xml :
<page string="BOM">
<field colspan="4" name="my_lines" string="bom lines" widget="one2many_list">
<tree editable="bottom">
<field name="field1"/>
<field name="field2"/>
</tree>
</field>
</page>
But I have no result? the problem is how to fil the result in my view?
Any help plz?
On which field you are calling
onchange_my_field
method in xml?in my_field : <field name="my_field" on_change="onchange_my_field(my_field, field1,field2)"/>
Make sure query returns the value. Try to print value of
vals
beforereturn
statement and see what is the output.It returns : [{ 'produit' : u'mp1' , 'qty': 10.0 } , {'product' : u'mp2' , 'qty' : 53.0 }]