+91-903-347-2982,+91-987-935-4457   contact@serpentcs.com

As an OpenERP/Odoo Developer, you might come across such a situation where you would like to make one or some fields read only or mandatory or hide ('invisible' in Odoo terminology) based on the values of other fields. The solution here to your situation is 'attrs'. The attrs is an element in Odoo 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 Odoo 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 : <field name="value_amount"

attrs="{'readonly':[('value','=','balance')],  'invisible': ['|',('service','in',[ODOO Support',ODOO 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.

<field name="tax_code_root_id" attrs="{'required': [('parent_id', '=', False)]}"/>

 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 

LEARN WHAT'S NEW IN ODOO V13
AUGUST 28, 2019 - WEDNESDAY


18:00 HOURS IST TO
19:00 HOURS IST
 
TYPE: FREE
BECOME AN ODOO CHAMP
JOIN OUR TRAINING, BE PREPARED FOR ODOO CERTIFICATION!
Contact Us For
Corporate | Personalised Training at our Premises or Online

ENROLL NOW
CHECK OUT OUR APP AT  
ODOO APP STORE
 
user image
Dhiraj Patel On, 6 January 2019

Hello sir, Good evening, sir i want to your odoo/ERP documentation link. if you want so i can also pay for it.