Odoo Help

Welcome!

This community 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.

0

how to show result dictfetchall in columns?

By
fdim
on 6/5/13, 7:12 AM 2,752 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)),
        }
        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?

Sudhir Arya (SA)
on 6/5/13, 7:20 AM

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

fdim
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 (SA)
on 6/5/13, 7:40 AM

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

fdim
on 6/5/13, 7:48 AM
3

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 6/5/13, 8:07 AM

Try this:

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

no result!!

fdim
on 6/5/13, 8:18 AM

Did you restart the server?

Sudhir Arya (SA)
on 6/5/13, 8:21 AM

yes i did

fdim
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 (SA)
on 6/5/13, 8:30 AM

nothing changed !

fdim
on 6/5/13, 9:06 AM

any other suggestion ?

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

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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