콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
11294 화면

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()
아바타
취소
베스트 답변

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

아바타
취소
작성자

Thanks Jack !

Your problem solve then accept answer

관련 게시물 답글 화면 활동
2
4월 21
15554
0
8월 16
3109
1
3월 15
4991
1
7월 25
624
4
2월 25
2873