Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
8802 Tampilan

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?

Avatar
Buang

On which field you are calling onchange_my_field method in xml?

Penulis

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 before return statement and see what is the output.

Penulis

It returns : [{ 'produit' : u'mp1' , 'qty': 10.0 } , {'product' : u'mp2' , 'qty' : 53.0 }]

Jawaban Terbai

Try this:

return {'value': {'my_lines': vals}}
Avatar
Buang
Penulis

no result!!

Penulis

yes i did

Try it again by removing field,field2` parameter from py and xml.

Like this:

my_field" on_change="onchange_my_field(my_field)
Penulis

nothing changed !

Penulis

any other suggestion ?

Jawaban Terbai

can you solve this? i have the same problem, any suggestions?

Avatar
Buang