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

Is it possible to compare fields in views using external id (not internal one). I need this because I need to hide some fields depending on another fields. I can make this work using internal database id. So if user chooses for example country (in view it checks that countries id), if id matches in view that it is compared, it shows another field. For example like this:

<field name="some_field"
    attrs="{'invisible': [('country_id','!=',10)]}"
/>

This one works, but it is not really reliable. Imagine if id would change (for example installing my module that id would be already taken by some other country), then it would show some_field when different country would be chosen. And that is not intended. So I thought about using external id, which you provide when adding data into tables in xml files. That id is static and actually should be the same for any database you would install that module (because that id is provided in module itself, not created by database automatically). Is there a way to use this same feature, but using external id? Of course maybe someone knows better approach to solve such problem? P.S. adding another field like boolean to show hide some_field is not an option, because it depends entirely on specific values that would be added on module install.

아바타
취소
베스트 답변

You can use fields_view_get to add this functionality. For example

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    if context is None:context = {}
    res = super(your_osv_class_name, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
    doc = etree.XML(res['arch'])
    nodes = doc.xpath("//field[@name='some_field']")
    id_found = self.pool.get('res.country').search(cr, uid,[('name','=','India')])[0]
    #or try to search for the id using the external id
    for node in nodes:
        node.set('attrs', "{'invisible':[('country_id','=',%s)]}"%id_found)
        setup_modifiers(node, res['fields']['some_field'])
    res['arch'] = etree.tostring(doc)
    return res
아바타
취소
작성자

Thanks. This looks useful.

관련 게시물 답글 화면 활동
1
3월 24
6840
1
10월 22
9810
2
9월 24
4579
6
9월 17
8357
2
3월 15
10015