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

what i'm doing 

@api.multi 

 @api.onchange('term_of_employment_id') 

 def _term_of_employment_onchange(self): 

 for rec in self:            

if rec.term_of_employment_id.type: 

 if rec.term_of_employment_id.type == 'fixed': 

 print("===========> I Run") 

 return {'attrs': {'tag': [('invisible', '=', False)]}}

its print I Run statement but can not invisible tag field 

pls point out where im wrong or any solution please 

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

Hi Usman,

You cannot hide a field from the py file using attrs. Either use attrs in XML or if your condition is complex then you can create a boolean field, change its value from onchange / compute field and use it in attrs.

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

Hi,

You can create a compute(or write value to the field in onchange)  Boolean field in the corresponding model and using this field value you can make the other field invisible.


role = # your role field definition
hide = field.Boolean(string='Hide', compute="_compute_hide")

@api.depends('role')
def _compute_hide(self):
    # simple logic, but you can do much more here
    if self.role == 'testrole':
         self.hide = True
    else:
         self.hide = False

Then in the XML,


<field name="fieldToHide" attrs="{'invisible':[('hide', '=', True)]}" />


See this sample here: https://stackoverflow.com/questions/38127562/hide-field-odoo-in-python-onchange-method

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

working like a charm you are always out of the box (y)

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
4704
0
thg 1 25
1453
0
thg 4 24
936
0
thg 11 23
1214
0
thg 6 23
2209