From 5041f63b353c82267b8669dfb0811e15246ef6d4 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 11 Mar 2014 16:04:46 +0100 Subject: [PATCH] [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 --- addons/crm/crm_lead.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 28f89533ac3..bd3c6f33f4e 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -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):