Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
8271 Lượt xem

HELLO GUYS:

I want to make a field invisble in the view xml.

I want to create function and call the function in my wml and there decide if the field will be invisible or not just like with DOMAIN.

Can anyone help me know how to realise that.

Thanks a lot ;)

Ảnh đại diện
Huỷ bỏ

post your code , that you have done so far

Câu trả lời hay nhất

Hi Dress 

Try using this as example :

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):

if not context: context = {}

res = super(your_class_name, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

#call your_function_here

doc = etree.XML(res['arch'])

if your_function_condition :

    nodes_your_field_name = doc.xpath("//field[@name='your_field_name']")

    for node in nodes_your_field_name:

    node.set('invisible', 'True')

res['arch'] = etree.tostring(doc)

return res


Don't forget to import the library

from lxml import etree

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Here is the XML code.

                                        <field name="structure_salariale" on_change="onchange_structure(structure_salariale,type_id)" attrs="{'invisible':[('name_contract','in', ['Mandataire','SIVP'])], 'required':[('name_contract','not in', ['Mandataire','SIVP'])]}"/>

But, i want to use a function to controle this not in xml.

But, question is can we use function with invisible attribute

Ảnh đại diện
Huỷ bỏ

override the fields_view_get of the model

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 23
12549
3
thg 7 22
22852
2
thg 6 21
18366
0
thg 9 20
3638
0
thg 2 17
2798