In Odoo 9, i am using on_change function and i need to hide some custom fields in view sale order
in models.py i have:
...
#Selecction Field
b = fields.Selection([('hide', 'Hide'),('nohide', 'Not Hide'),('choiceoption', 'Choice Option')], default='choiceoption')
b_value = fields.Char('Value', default='Hello')
b_unit = fields.Char('Unit', readonly='True', default='World')
#Function
def on_change_b(self,cr,user,ids,b,b_value,b_unit,context=None):
if b=='choiceoption':
v = {'b_value': 'Choice Option', 'b_unit': 'Choice Option'}
return {'value': v}
elif b=='nohide':
v = {'b_value': 'No Hide Field b_value', 'b_unit': 'No Hide Field b_unit'}
return {'value': v}
else:
v = {'b_value': 'Yes Hide Field b_value', 'b_unit': 'Yes Hide Field b_unit'}
return {'value': v}
...
in templates.xml i have:
...
<field name="b" on_change="on_change_b(b, b_value, b_unit)" />
<field name="b_value" />
<field name="b_unit" />
...
1.- How i can hide the field "b_value" and "b_unit" when i choice "Hide" in the selection field, i think this must be writed in the function "on_change_b" but i do not know how doit the code, maybe with "attrs"
2.- How to initialize a field with invisible = yes for default like:
fieldxyz = fields.Char('This is Field XYZ', default=This is the value of fieldxyz', attrs="{'invisible':true}") <---This is correct?