Odoo Help

0

How to get value of one2many fields ?

By
Ajeng Shilvie
on 1/17/15, 2:40 AM 1,677 views

I make onchange_method in custom module many2one field like this :

    def onchange_branch_collecting(self, cr, uid, ids, branch_id):

        default = {
            'value':{},
        }
        
        wo_pool = self.pool.get('wtc.work.order')
        wo_search = wo_pool.search(cr,uid,[
                                    ('branch_id','=',branch_id),
                                    ('kpb_collected','=','ok'),
                                    ('state','=','done')
                                    ])
        workorder = []
        if not wo_search :
            workorder = []
        elif wo_search :
            wo_browse = wo_pool.browse(cr,uid,wo_search)           
            for x in wo_browse :
                workorder.append([0,0,{
                                 'id':x.id,
                                 'name':x.name,
                                 'lot_id':x.lot_id.id,                                 
                                 'chassis_no':x.chassis_no,
                                 'date':x.date,
                                 'type':x.type,
                                 'kpb_ke':x.kpb_ke,
                                 'km':x.km,
                                 'state':x.state,
                                 'kpb_collected':x.kpb_collected,   
                
                }])
                
        default['value'].update({'work_order_ids': workorder})
        return default

and i override create button like this :

    def create(self,cr,uid,vals,context=None):
        print "ini value vals",vals
        
        wo_collect = []
        for x in vals['work_order_ids']:
            wo_collect.append(x)
        print "ini daftar work order",wo_collect
        del[vals['work_order_ids']]
        
        collecting_id = super(wtc_collecting_kpb, self).create(cr, uid, vals, context=context)
        if collecting_id :
            print "ada hahahahah"
        wo_pool = self.pool.get('wtc.work.order')
        wo_search = wo_pool.search(cr,uid,[
                                    ('branch_id','=',vals['branch_id']),
                                    ('kpb_collected','=','ok'),
                                    ('state','=','done'),
                                    ('collecting_id','=',False),
        
                                    ])
        wo_browse = wo_pool.browse(cr,uid,wo_search)
        print "ini ajeng"            
        for y in wo_browse :
            for z in wo_collect :
                if z['name'] == y.name :   #this condition is error 
                    y.write({
                           'kpb_collected':'collected',
                           'collecting_id':collecting_id,
                           })
        return collecting_id

the problem is  , i want to get value name in wo_collect  . But still not work error message show up it said not mathing apples and orange .

1

Try to debug/print the value of z['name']. It gives the feeling that "type" of both operands i.e z['name'] and 'y.name' is different. That means the datatype of both the values that you are tyring to compare is different.
 

yes you were right , i found the answer thanks

Ajeng Shilvie
on 1/17/15, 8:16 AM

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.

Register

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

1 follower(s)

Stats

Asked: 1/17/15, 2:40 AM
Seen: 1677 times
Last updated: 3/16/15, 8:10 AM