I am trying to pull data from one table to other on the basis of id in table-1. I am having two tables: othertable1 & othertable2. I want to show the value of field1 of othertable1 in field3 of othertable2 if field1==field4. I ahve tried writing this code, but getting Key Error: (id). So please guide me folks.
from osv import osv, fields
import time
import datetime
import pooler
class pka_learning_othertable1(osv.osv):
_name="pka.learning.othertable1"
_description = 'Get Data From Other Table; This is Other Table-1'
_columns={
'field1':fields.char('Field-1', size=20),
'field2':fields.char('Field-2', size=20)
}
pka_learning_othertable1()
class pka_learning_othertable2(osv.osv):
_inherit="pka.learning.othertable1"
_name="pka.learning.othertable2"
_description = 'Get Data From Other Table; This is Other Table-2'
def _get_other_table1(self, cr, uid,ids, field_names, args, context=None):
res = {}
#other_table1 = self.pool.get('pka.learning.othertable1')
other_table1 = self.pool.get('pka.learning.othertable1')
for record in self.browse(cr, uid, ids, context=context):
other_table2 = other_table1.search(cr, uid, [('id','=',record.id)])
for rec in other_table1.browse(cr, uid, other_table2, context=None):
if rec.field1:
res[id] = rec.field1
return res
_columns={
'field3':fields.function(_get_other_table1, string='Field-3'),
'field4':fields.char('Field-4', size=50)
}
pka_learning_othertable2()