Change_default in OpenERP

There are many useful features in OpenERP that is not either used by much people or may be they do not know about it or may be they heard about it but didn’t understand the functionality / working of these features. Let’s discuss it here… many more to come in the upcoming blogs…wait and watch

One of them is the CHANGE_DEFAULT attribute of a field.

Change_default: Whether or not the user can define default values on other fields depending on the value of the field having the change_default set.

This is one of the attribute that needs to be defined when you define your field for the OpenERP model (class). lets see an example

Class attribute_test(osv.osv):






zip: fields.char(‘zip’, size=64, change_default=True),

city:fields.char(‘zip’, size=64)



Now you would  have these fields displayed in your form view. Till here we saw the declaration of this attribute. now we see how we can use it

Now go to the field for which you want to set a default value, in our case its CITY enter the value for city say Gandhinagar, just right click on this field and select set as default (GTK Client ) or click set as default from the right panel(Web Client)  then you will see the ZIP field avaialble with a checkbox, tick that field and say OK. here say the field ZIP has a value 382024.  You have the option to set the default value for All users or just for your self.



Note 1: For web 6.1 the fields that are invisible / readonly / One2Many / Many2Many will not appear in set as default menu.

How the effect is known ?

So whenever you enter the value for the field ZIP as 382024 and hit a TAB to have the focus_out event triggered you will see the CITY is automatically field to Gandhinagar.

Note 2: You can place change_default attribute on more then one field but you can use only one of them to set the default value for the targeted field.