I added that method :
def _get_coefficient_value(self, cr, uid, context=None):
stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
if stage.probability > 50:
x_coefficient = 0.1
elif value < 50:
x_coefficient = 1
else:
x_coefficient = 0.5
return x_coefficient
and on create method on crm_lead.py, i added the line :
vals['x_coefficient'] = self._get_coefficient_value(cr, uid, context=ctx)
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
if not vals.get('stage_id'):
ctx = context.copy()
vals['x_coefficient'] = self._get_coefficient_value(cr, uid, context=ctx)
if vals.get('section_id'):
ctx['default_section_id'] = vals['section_id']
if vals.get('type'):
ctx['default_type'] = vals['type']
vals['stage_id'] = self._get_default_stage_id(cr, uid, context=ctx)
return super(crm_lead, self).create(cr, uid, vals, context=context)
But when i create new opportunity, coefficient field == 0 whatever the stage of the opportunity.
I want when you save new opportunity, to execute _get_coefficient_value, and my field coefficient should be calculated automatically depending on the stage.