0
votes

I'm newbie in OpenERP developpement, and i want to add some fields to opprotunity form view.

1) I want to add Picklist field for Stages.

2) I want to add new field of type float (coefficient), ReadOnly and it depends on opportunity's probalility on the timing of creation:

                If probability <50% then coefficient == 1  
                Else if probability >50% then coefficient == 0.1
                Else coefficient == 0.5

Once the coefficient is calculated for the first time, it should not be changed.

2

2 Answers

1
votes

You need to inherit the model first to add your custom fields, then inherit the view and add the fields in the view (tree, form, search etc). Creating your own custom module to do this is the best way to implement it.

More information on inheriting can be found here Object Inheritance

and view inheritance in Inheritance in Views

0
votes

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.