How to set default values ​​using methods in Odoo 8?

How to calculate value for default value in object fields in Odoo 8 models.py

We cannot use the _default attribute anymore in Odoo 8.

 field_name = fields.datatype( string='value', default=compute_default_value ) 

In the field declaration above, I want to call a method to assign a default value for this field. For example:

 name = fields.Char( string='Name', default= _get_name() ) 

Please help me with this.

+8
python odoo odoo-8
source share
2 answers

You can use the lambda function as follows:

 name = fields.Char( string='Name', default=lambda self: self._get_default_name(), ) @api.model def _get_default_name(self): return "test" 
+12
source share

A simpler version for @ChesuCR's answer:

 def _get_default_name(self): return "test" name = fields.Char( string='Name', default=_get_default_name, ) 
+9
source share

All Articles