[FIX] crm: write a value to date_closed field as well if change directly the stage instead of using buttons (which will probably be removed later)

bzr revid: mat@openerp.com-20140311150446-0atbc6esymjyv69e
This commit is contained in:
Martin Trigaux 2014-03-11 16:04:46 +01:00
parent 8db1b77757
commit 5041f63b35
1 changed files with 6 additions and 3 deletions

View File

@ -926,11 +926,14 @@ class crm_lead(base_stage, format_address, osv.osv):
return res
def write(self, cr, uid, ids, vals, context=None):
if vals.get('stage_id') and not vals.get('probability'):
# change probability of lead(s) if required by stage
if vals.get('stage_id'):
stage = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
if stage.on_change:
if not vals.get('probability') and stage.on_change:
# change probability of lead(s) if required by stage
vals['probability'] = stage.probability
# set closed date when won or lost
if not vals.get('date_closed') and (vals.get('probability', 0) >= 100 or stage.state == 'canceled'):
vals['date_closed'] = fields.datetime.now()
return super(crm_lead, self).write(cr, uid, ids, vals, context=context)
def copy(self, cr, uid, id, default=None, context=None):