I have three fields in a table- name1, name2, cost. I already created a form for saving these fields,
And i have another form(another table)---here name1,name2 are many2one fields. When i select these two names Compare the two many2one field, its corresponding value of cost selects from the that table to this form.
How can i write a code for this?
form1 or table1
class cost()
'name1' : fields.many2one('name1.name1', required= true)
'name2' ; fields.many2one('name2.name2', required=true)
'cost' : fields.integer('Name',required=true)
cost()
eg: ram sam 1500 john sabu 43
form2 or table2
class select()
'name1' : fields.many2one('name1.name1', required= true)
'name2' ; fields.many2one('name2.name2', required=true)
'select_cost' : compare name1 and name2 select the cost from the first table1
ie, if i select ram,sam then the cost is 1500 in select_cost field or if john or sabu then cost is 43.
how can i write the code in the select_cost field?
How to use select query here?
You have to use on_change() in the view definition of the secong program, and should give the many2one field ids as arguements. And with that arguements, you have to retrieve the cost from the first model. self.pool.get('first_model_name').search(cr,uid,[('name1','=',name1)('name2','='name2)],context=None) after running this command you will get the respective record ids and pass that id to browse that record. you will get browse_record of the first model. then you can retrieve the cost from the first table using . operator to that browse record. and return {'value':value['select_cost']=cost}
Hi Abhishek, I'm new in python code. Can u please brief the code? Awaiting your reply.
Please update the code it as answer.
Please use the above field name, that i can easily recognize the code.
class first_mod(osv.osv):
Hi Abhishek, please complete the code. Awaiting your reply. Its urgent for me,please