As an OpenERP Developer, you might come across such a situation where
you would like to make one or some fields readonly or mandatory or hide
(‘invisible’ in OpenERP terminology) based on the values of other
fields.
Well, then you are getting OpenERP Training just by reading this as the solutions here are explained by well versed OpenERP Trainers.
The solution here to your situation is ‘attrs’.
The attrs is an element in OpenERP which is responsible to alter the attributes of a field, not the value. The ‘attrs’ attribute can be used to dynamically change the attributes of view components based on the value of other fields. Buttons in OpenERP use states attribute for dynamic visibility, they too can be used with attrs. It can be used on field, page, group, button and notebook tags. Remember, there is no RPC call ever made because this is a pure client side attribute at view level.
The structure of ‘attrs‘ is a dictionary carrying the key as the client attribute and value as a set of domain(s),the keys could be:
Structure : attrs=”{‘attribute’:Domain which is if true, the element will wear the new property ‘attribute’}”
Syntax of attrs :
attrs=”{‘required’: [('parent_id', '=', False)]}”
/>
Well, then you are getting OpenERP Training just by reading this as the solutions here are explained by well versed OpenERP Trainers.
The solution here to your situation is ‘attrs’.
The attrs is an element in OpenERP which is responsible to alter the attributes of a field, not the value. The ‘attrs’ attribute can be used to dynamically change the attributes of view components based on the value of other fields. Buttons in OpenERP use states attribute for dynamic visibility, they too can be used with attrs. It can be used on field, page, group, button and notebook tags. Remember, there is no RPC call ever made because this is a pure client side attribute at view level.
The structure of ‘attrs‘ is a dictionary carrying the key as the client attribute and value as a set of domain(s),the keys could be:
- readonly
- invisible
- required
Structure : attrs=”{‘attribute’:Domain which is if true, the element will wear the new property ‘attribute’}”
Syntax of attrs :
attrs=
”{‘readonly’:[('value','=','balance')],
‘invisible’: ['|',('service','in',['OpenERP Support','OpenERP
Training']),(‘company’,'=’,'SerpentCS’)]}”
/>
Result : If the domains are satisfied, the field ‘value_amount’ will be readonly in 1st case and will be hidden on 2nd case.
You can use any domains here but make sure there will be no server side calls made. So better to be limited at view level.
Attrs is reflected at view level per record, and hence that can never be applied at List view/ Tree view level.
Hope this makes you hungry to learn more about the beauty of OpenObject Framework. You can take the advantages of learning this greatly with us by attending our trainings.
Thanks,
Serpent Consulting Services
No comments:
Post a Comment