[IMP] crm: Historize changes on Stage for Leads and Opportunities.

bzr revid: uco@tinyerp.com-20101101094617-oujei764tfi1hpo5
This commit is contained in:
uco (OpenERP) 2010-11-01 15:16:17 +05:30
parent 535205d836
commit 37be991751
4 changed files with 21 additions and 3 deletions

View File

@ -286,11 +286,19 @@ class crm_lead(crm_case, osv.osv):
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.onchange_stage_id(cr, uid, ids, stage)
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:
for case in self.browse(cr, uid, ids):
self.onchange_stage_id(cr, uid, [case.id], case.stage_id.id)
return stage
def message_new(self, cr, uid, msg, context):
"""
Automatically calls when new email message arrives

View File

@ -57,7 +57,8 @@
<newline />
<field name="section_id" widget="selection" />
<field name="user_id" />
<field name="stage_id" domain="[('object_id.model', '=', 'crm.lead'), ('section_ids', '=', section_id)]"/>
<field name="stage_id" domain="[('object_id.model', '=', 'crm.lead'), ('section_ids', '=', section_id)]"
on_change="onchange_stage_id(stage_id)"/>
<group col="2" colspan="1">
<button name="stage_previous" string=""
states="open,pending,draft" type="object"

View File

@ -142,11 +142,18 @@ class crm_opportunity(osv.osv):
@param uid: the current users ID for security checks,
@param ids: List of stages IDs
@stage_id: change state id on run time """
if not stage_id:
return {'value':{}}
stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
self.history(cr, uid, ids, _('Stage'), details=stage.name)
for case in self.browse(cr, uid, ids):
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 not stage.on_change:
return {'value':{}}
return {'value':{'probability': stage.probability}}

View File

@ -250,6 +250,8 @@ class mailgate_message(osv.osv):
elif message.name == _('Note'):
msg_txt = (message.user_id.name or '/') + _(' added note on ') + format_date_tz(message.date, tz) + ':\n\t'
msg_txt += self.truncate_data(cr, uid, message.description, context=context)
elif message.name == _('Stage'):
msg_txt += _("Changed Stage to: ") + message.description
else:
msg_txt += _("Changed Status to: ") + message.name
result[message.id] = msg_txt