2017-11-29 4 views
3

한 모델에 selection 필드를 정의했습니다. 키 대신 선택 필드 값 가져 오기

type = fields.Selection([('a','A'),('b','B'),('c','C')]) 

기능 중 하나에서 난 string value 대신 key을 얻기 위해 노력했다.

@api.multi 
    def testFunc(self): 
    for res in self: 
     print'Value',res.type //It prints 'a'. 

'A'를 인쇄해야합니다.

어떻게하면됩니까?

답변

2

솔루션 중 하나를 선택

이 같은 선택 목록 얻을 수있는 가장 가져 오는 것은 :

self._fields['type'].selection 

그래서이 시도 : 당신이 원하는 경우

# convert the list to dictionary 
    dict(self._fields['type'].selection).get(self.type) 

을 사용자 언어로 번역 할 레이블 :

# here the label return is translated. 
    value = dict(self.fields['state']._description_selection(self.evn)).get(self.type) 
+0

감사합니다 @ Tchi-Odoo, 작동합니다. – KbiR