dynamically set field default value

Tag: openerp Author: jljlcza Date: 2013-10-20

I'm doing following:

def default_get(self, cr, uid, fields, context=None):
    data = super(extended_projects, self).default_get(cr, uid, fields, context=context)
    data['test_field'] = context.get('test_field','default_value')
    return data

This works and sets the default values.

But I need to set it dynamically, specifically in the fields_view_get method (which I'm overriding as well).

if I do this (in fields_view_get):

context['test_field'] = 'new_default_value'
test_data = self.default_get(cr, uid, ['test_field'], context=context)

The new default value doesn't show for the field.

Other Answer1

if you want to load data to a field from other than default_get function or _defaults dictionary, then in the context add a key called 'default_your_field' and its value. for example context['default_test_field'] ='new_default_data'. then pass this context


thanks I will give this a try and if it works accept your answer