[IMP] crm: Task ID-1796, historizing lead/opportunity stage changes using write method. Removed code from button click event.

bzr revid: uco@tinyerp.com-20101115121736-n4zlvrwh92gl2xj8
This commit is contained in:
uco (OpenERP)
2010-11-15 17:47:36 +05:30
parent f3a868e28d
commit 61440d2346
2 changed files with 17 additions and 32 deletions
+15 -21
View File
@@ -192,7 +192,6 @@ class crm_lead(crm_case, osv.osv):
if not old_stage_id:
stage_id = super(crm_lead, self).stage_next(cr, uid, ids, *args)
if stage_id:
value.update({'stage_id': stage_id})
value.update(self.onchange_stage_id(cr, uid, ids, stage_id, context={})['value'])
value.update({'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
self.write(cr, uid, ids, value)
@@ -282,35 +281,30 @@ class crm_lead(crm_case, osv.osv):
}
return value
def write(self, cr, uid, ids, vals, context={}):
if 'date_closed' in vals:
return super(crm_lead,self).write(cr, uid, ids, vals, context)
if 'stage_id' in vals and vals['stage_id']:
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
self.history(cr, uid, ids, _('Stage'), details=stage_obj.name)
for case in self.browse(cr, uid, ids, context=context):
if case.type == 'lead':
message = _("The stage of lead '%s' has been changed to '%s'.") % (case.name, case.stage_id.name)
elif case.type == 'opportunity':
message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, case.stage_id.name)
self.log(cr, uid, case.id, message)
return super(crm_lead,self).write(cr, uid, ids, vals, context)
def stage_next(self, cr, uid, ids, context=None):
stage = super(crm_lead, self).stage_next(cr, uid, ids, context)
if stage:
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context)
self.history(cr, uid, ids, _('Stage'), details=stage_obj.name)
for case in self.browse(cr, uid, ids, context=context):
if case.type == 'lead':
message = _("The stage of lead '%s' has been changed to '%s'.") % (case.name, case.stage_id.name)
elif case.type == 'opportunity':
message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, case.stage_id.name)
self.log(cr, uid, case.id, message)
if stage_obj.on_change:
data = {'probability': stage_obj.probability}
self.write(cr, uid, ids, data)
return stage
def stage_previous(self, cr, uid, ids, context=None):
stage = super(crm_lead, self).stage_previous(cr, uid, ids, context)
if stage:
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context)
self.history(cr, uid, ids, _('Stage'), details=stage_obj.name)
for case in self.browse(cr, uid, ids, context=context):
if case.type == 'lead':
message = _("The stage of lead '%s' has been changed to '%s'.") % (case.name, case.stage_id.name)
elif case.type == 'opportunity':
message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, case.stage_id.name)
self.log(cr, uid, case.id, message)
return stage
def message_new(self, cr, uid, msg, context):
"""
Automatically calls when new email message arrives
+2 -11
View File
@@ -60,11 +60,7 @@ class crm_opportunity(osv.osv):
@param *args: Tuple Value for additional Params
"""
res = super(crm_opportunity, self).case_close(cr, uid, ids, args)
stage_id = super(crm_opportunity, self).stage_next(cr, uid, ids, context={'force_domain': [('probability', '=', 100)]})
if not stage_id:
raise osv.except_osv(_('Warning !'), _('There is no stage for won opportunities defined for this Sale Team.'))
value = self.onchange_stage_id(cr, uid, ids, stage_id, context={})['value']
value.update({'date_closed': time.strftime('%Y-%m-%d %H:%M:%S'), 'stage_id': stage_id})
value = {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')}
self.write(cr, uid, ids, value)
for (id, name) in self.name_get(cr, uid, ids):
@@ -83,12 +79,7 @@ class crm_opportunity(osv.osv):
@param *args: Tuple Value for additional Params
"""
res = super(crm_opportunity, self).case_close(cr, uid, ids, args)
stage_id = super(crm_opportunity, self).stage_next(cr, uid, ids, context={'force_domain': [('probability', '=', 0)]})
value = {}
if stage_id:
value = self.onchange_stage_id(cr, uid, ids, stage_id, context={}).get('value', {})
value['stage_id'] = stage_id
value.update({'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')})
value = {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')}
res = self.write(cr, uid, ids, value)
for (id, name) in self.name_get(cr, uid, ids):