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

Hi, I'm trying to figure out how to return domains for various fields in a single function, with @onchange decorator. Is this possible or I have to do cascade functions like after the first onchange function I have to use another one for the other domain? can I use 2 times the @onchange decorators? I've tried that before but without positive results.


Regards




아바타
취소
작성자 베스트 답변

@Niyas

That code seems good but when I tried in Odoo 11 didn't worked for my custom model, Also i have to return 2 or more domains. so the workaround i've used is a chain onchange-decorated functions. like 


@api.onchange(a_field)

def domainB(self)

  #build the domain string

   return domainB


@api.onchange(b_field)

def domainC(self)

  #build the domain string

  return domainC


Assuming I have to change the A and B fields to trigger the functions, I've used the form to guide the user through the proccess, making the B and C fields invisible if they don't choose a value for A field(required) first. 



아바타
취소
베스트 답변

Hi,

I think in the onchange itself it is possible. See the function named _change_model_id in the gamification module.


@api.onchange('model_id')
def _change_model_id(self):
"""Force domain for the `field_id` and `field_date_id` fields"""
if not self.model_id:
return {'domain': {'field_id': expression.FALSE_DOMAIN, 'field_date_id': expression.FALSE_DOMAIN}}
model_fields_domain = [
('store', '=', True),
'|', ('model_id', '=', self.model_id.id),
('model_id', 'in', self.model_id.inherited_model_ids.ids)]
model_date_fields_domain = expression.AND([[('ttype', 'in', ('date', 'datetime'))], model_fields_domain])
return {'domain': {'field_id': model_fields_domain, 'field_date_id': model_date_fields_domain}}

Thanks

아바타
취소
관련 게시물 답글 화면 활동
2
7월 24
7869
2
2월 24
15605
1
12월 22
5035
2
12월 22
14529
2
6월 22
6400