2017-04-12 3 views
2

필드가 비어 있으면 어떻게 체크 할 수 있습니까? 이 코드가 어떻게 올바르게 보일 것입니다.다른 모듈의 Odoo 체크 필드

제 희망을 분명히 밝히기를 바랍니다.

def method(self, vals): 
    if vals.get("field" == empty) 
    use my logic 
    if not empty use data that was already there. 
    and if that field is in other model , how can i reach it. 
+0

여기 vals의 유형은 무엇입니까? – Cherif

답변

2

이 시도 :

def method(self): 
    if vals.get("field_name", False): 
     # Code if is not empty 
    else: 
     # Code if is empty 
1

당신은 코드를 다음 시도 할 수있는 첫 번째 검사에서 키 발스 또는없는 경우. 키가 이용 가능한 경우, 체크 값이 설정되는지의 여부. 필드가 비어 있지 및 필드가 다른 모델에있는 경우

def method(self, vals): 
    if vals.has_key('field') and not vals.get('field',False): 
     print "if logic" 
    else: 
     print "else logic" 

당신은 active_model으로 시도해야합니다.

귀하는 기록을 찾아 보거나 다른 작업을 수행 할 수 에 따라 호출 방법에서 맥락에서 active_model를 전달할 수 있습니다.

예 : WITH_CONTEXT 사용자를 사용

def method(self, vals): 
    if vals.has_key('field') and not vals.get('field',False): 
     print "if logic" 
    else: 
     model=self._context.get('active_model') 
     self.env[model].browse(model) 
     print "else logic" 

self.with_context({'active_model':'model'}).method(vals) 

이 통과 할 수 컨텍스트 값에 따라 상황에 맞는 & 당신은 쉽게 동적으로 활성화 모델을 얻을 수 있습니다.

이 정보는 도움이됩니다.

1
def method(self, vals): 
    if not vals.get('field'): 
     #if empty use your logic 
    else: 
     #if not empty use data that was already there. 
     #to print field value: 
     print vals['field'] 

      #and if that field is in other model , how can i reach it. 
     you may reach it by search that field in other model.