Skip to Content
Menú
This question has been flagged
2 Respostes
11304 Vistes

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()
Avatar
Descartar
Best Answer

Hi

Try below code

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[record.id] = rec.field1

return res

Thanks

Avatar
Descartar
Autor

Thanks Jack !

Your problem solve then accept answer

Related Posts Respostes Vistes Activitat
2
d’abr. 21
15558
0
d’ag. 16
3117
1
de març 15
4994
1
de jul. 25
633
4
de febr. 25
2886