Odoo Help


how to show result dictfetchall in columns?

on 6/5/13, 7:12 AM 3,818 views

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)),

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"/> 



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?

Sudhir Arya (ERP Harbor Consulting Services)
on 6/5/13, 7:20 AM

in my_field : <field name="my_field" on_change="onchange_my_field(my_field, field1,field2)"/>

on 6/5/13, 7:31 AM

Make sure query returns the value. Try to print value of vals before return statement and see what is the output.

Sudhir Arya (ERP Harbor Consulting Services)
on 6/5/13, 7:40 AM

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

on 6/5/13, 7:48 AM

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 6/5/13, 8:07 AM

Try this:

return {'value': {'my_lines': vals}}

no result!!

on 6/5/13, 8:18 AM

Did you restart the server?

Sudhir Arya (ERP Harbor Consulting Services)
on 6/5/13, 8:21 AM

yes i did

on 6/5/13, 8:22 AM

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

Like this:

my_field" on_change="onchange_my_field(my_field)
Sudhir Arya (ERP Harbor Consulting Services)
on 6/5/13, 8:30 AM

nothing changed !

on 6/5/13, 9:06 AM

any other suggestion ?

on 6/5/13, 12:06 PM
On 9/22/14, 10:58 AM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 6/5/13, 7:12 AM
Seen: 3818 times
Last updated: 3/16/15, 8:10 AM