Odoo Help

1

Get value from many2one relationship ?

By
Trai Doan
on 11/25/14, 10:29 PM 2,164 views

My codes :

class name(osv.osv):
        _name='name.model'
        _columns={
                  'name':fields.char('Name',size=32),
                  'ten':fields.char('Ten',size=40),
                  'so':fields.integer('So luong'),
                  'cost':fields.integer('Cost'),
                  }
name()

class first_model(osv.osv):
        _name='first.model'
        _columns={
                  'name':fields.char('Name',size=32),
                  'name1':fields.many2one('name.model','Relationship'),
                  'number':fields.integer('Number'),
                  }
first_model()

class second_model(osv.osv):
        _name='second.model'
        _columns={
                  'name':fields.char('Name',size=50),
                  'name2':fields.many2one('first.model','Choose'),
                  'cost':fields.integer('Cost')         
                  }
        def onchange_cost(self,cr,uid,ids,name2,context=None):
            value={}
            if name2:
                record=self.pool.get('first.model').browse(cr,uid,name2,context=context)
                if record:
                    print record.name1
                    recor_id=self.pool.get('name.model').search(cr,uid,[('name','=',record.name1)],context=context)
                    if recor_id:
                        rec=self.pool.get('name.model').browse(cr,uid,recor_id,context=context)
                        print rec.cost

second_model()

My problem is when i try to get cost from name.model it always return empty .I check value of record.name1 and its look like : name.model(3,) or name.model(5,) .How can i get cost from name.model .Please help me to solve this .Thank you :)) 

Sorry for bad english :((

 

5
Baiju KS
On 11/25/14, 11:32 PM

Try this:-

record=self.pool.get('first.model').browse(cr,uid,name2.id,context=context)

please let me know if problem get solved.

Thank for your help :)) .Problem solved .

Trai Doan
on 11/25/14, 11:56 PM
0

Hello Trian

Try this

def onchange_cost(self,cr,uid,ids,name2,context=None):
    value={}
    name_model_cost = 0.00
    if name2:

        obj_first_model = self.pool.get('first.model')
        br_first_model =    obj_first_model.browse(cr,uid,name2,context=context)
        name_model_cost = br_first_model.name1 and br_second_model.name1.cost or 0.0

    return {'value':{'cost':name_model_cost}}
   

Hope this helps !!!

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

2 follower(s)

Stats

Asked: 11/25/14, 10:29 PM
Seen: 2164 times
Last updated: 6/7/16, 7:41 AM