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

Hi everyone

I'm trying to build a view using the fields_view_get method. To make the view adapt to the specific record i would like to hide some of the field groups by adding attrs="{'invisible'.....}".


Inspecting the view in the application reveals that the xml is built correctly, but still somehow the groups don't accept the invisible property and stay visible all the time, even if i set 'invisible' to 1.


 This here is the code:

@api.model
deffields_view_get(self, view_id, view_type=False, context=None, toolbar=False, submenu=False):
res = super(Equipment, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)print("VID: ", view_id)
    if view_type=='form':
        print("HELLO WORLD WFWEFWW")print(self.env.context)
        doc = ET.XML(res['arch'])​
        node = doc.findall(".//page[@name='additional_fields']")[0]

        cat_list = self.env['maintenance.equipment.category'].search([])

        group = ET.Element('group')node.append(group)
        for cat in cat_list:
            cat_group = ET.Element('group')
            cat_group.set('string',cat.name)
            cat_id = str(cat.id)
            invisible_string = "{'invisible':[('cat_id_nr','!=','2')]}"
            cat_group.set("attrs",invisible_string)
            group.append(cat_group)
            field_list = cat.test
            for field in field_list:
                print(field.name, "\n")
                el = ET.Element('field')
                el.set('name',field.name)
                cat_group.append(el)
            ET.indent(node, space="\t", level=0)
            res['arch'] = ET.tostring(doc)
            return res

I thank you in advance for your help!




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

Never mind, I found the solution myself. 

Instead of using attrs to set fields to invisible, fields_view_get requires one to use modifiers.

So by adding the following lines of code it worked.

modifiers = {}
#check for existing modifiers to not overrite anything
if cat_group.get("modifiers") is not None:
    modifiers = json.loads(cat_group.get("modifiers"))
    modifiers['invisible'] = [['cat_id_nr', '!=', cat_id]]
    cat_group.set("modifiers", json.dumps(modifiers))

I'm not sure if thats the proper way to do it, but it's a working way. If anyone has a better solution I would be happy to hear it. I'm still pretty new to odoo development ;)



아바타
취소
관련 게시물 답글 화면 활동
1
9월 23
1316
1
6월 25
1615
3
7월 25
3258
1
5월 25
1399
1
5월 25
1648