[IMP] crm_stage: add a default method to send notifications when changing stages. crm_lead: override this method.
bzr revid: tde@openerp.com-20120530090340-wma71ka6sojbqiyh
This commit is contained in:
parent
3b7ba480fc
commit
61f8305fcc
|
@ -142,6 +142,7 @@ class base_stage(object):
|
||||||
if hasattr(self, 'onchange_stage_id'):
|
if hasattr(self, 'onchange_stage_id'):
|
||||||
value = self.onchange_stage_id(cr, uid, ids, stage_id, context=context)['value']
|
value = self.onchange_stage_id(cr, uid, ids, stage_id, context=context)['value']
|
||||||
value['stage_id'] = stage_id
|
value['stage_id'] = stage_id
|
||||||
|
self.stage_set_send_note(cr, uid, ids, stage_id, context=context)
|
||||||
return self.write(cr, uid, ids, value, context=context)
|
return self.write(cr, uid, ids, value, context=context)
|
||||||
|
|
||||||
def stage_change(self, cr, uid, ids, op, order, context=None):
|
def stage_change(self, cr, uid, ids, op, order, context=None):
|
||||||
|
@ -363,6 +364,14 @@ class base_stage(object):
|
||||||
def case_get_note_msg_prefix(self, cr, uid, id, context=None):
|
def case_get_note_msg_prefix(self, cr, uid, id, context=None):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
|
||||||
|
""" Send a notification when the stage changes. This method has
|
||||||
|
to be overriden, because each document will have its particular
|
||||||
|
behavior and/or stage model (such as project.task.type or
|
||||||
|
crm.case.stage).
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
def case_open_send_note(self, cr, uid, ids, context=None):
|
def case_open_send_note(self, cr, uid, ids, context=None):
|
||||||
for id in ids:
|
for id in ids:
|
||||||
msg = _('%s has been <b>opened</b>.') % (self.case_get_note_msg_prefix(cr, uid, id, context=context))
|
msg = _('%s has been <b>opened</b>.') % (self.case_get_note_msg_prefix(cr, uid, id, context=context))
|
||||||
|
|
|
@ -88,10 +88,10 @@ class crm_lead(base_stage, osv.osv):
|
||||||
search_domain = []
|
search_domain = []
|
||||||
section_id = self._resolve_section_id_from_context(cr, uid, context=context)
|
section_id = self._resolve_section_id_from_context(cr, uid, context=context)
|
||||||
if section_id:
|
if section_id:
|
||||||
search_domain += ['|', '&', ('section_ids', '=', section_id), ('fold', '=', True)]
|
search_domain += ['|', '&', ('section_ids', '=', section_id), ('fold', '=', False)]
|
||||||
|
search_domain += ['|', ('id', 'in', ids), '&', ('case_default', '=', 1), ('fold', '=', False)]
|
||||||
if type:
|
if type:
|
||||||
search_domain += ['|', ('type', '=', type), ('type', '=', 'both')]
|
search_domain += ['|', ('type', '=', type), ('type', '=', 'both')]
|
||||||
search_domain += ['|', ('id', 'in', ids), '&', ('case_default', '=', 1), ('fold', '=', False)]
|
|
||||||
# perform search
|
# perform search
|
||||||
stage_ids = stage_obj._search(cr, uid, search_domain, order=order, access_rights_uid=access_rights_uid, context=context)
|
stage_ids = stage_obj._search(cr, uid, search_domain, order=order, access_rights_uid=access_rights_uid, context=context)
|
||||||
result = stage_obj.name_get(cr, access_rights_uid, stage_ids, context=context)
|
result = stage_obj.name_get(cr, access_rights_uid, stage_ids, context=context)
|
||||||
|
@ -369,7 +369,6 @@ class crm_lead(base_stage, osv.osv):
|
||||||
"""
|
"""
|
||||||
return self.set_priority(cr, uid, ids, '3')
|
return self.set_priority(cr, uid, ids, '3')
|
||||||
|
|
||||||
|
|
||||||
def _merge_data(self, cr, uid, ids, oldest, fields, context=None):
|
def _merge_data(self, cr, uid, ids, oldest, fields, context=None):
|
||||||
# prepare opportunity data into dictionary for merging
|
# prepare opportunity data into dictionary for merging
|
||||||
opportunities = self.browse(cr, uid, ids, context=context)
|
opportunities = self.browse(cr, uid, ids, context=context)
|
||||||
|
@ -847,22 +846,12 @@ class crm_lead(base_stage, osv.osv):
|
||||||
"You should better cancel it, instead of deleting it.") % lead.name)
|
"You should better cancel it, instead of deleting it.") % lead.name)
|
||||||
return super(crm_lead, self).unlink(cr, uid, ids, context)
|
return super(crm_lead, self).unlink(cr, uid, ids, context)
|
||||||
|
|
||||||
|
|
||||||
def write(self, cr, uid, ids, vals, context=None):
|
def write(self, cr, uid, ids, vals, context=None):
|
||||||
if not context:
|
if vals.get('stage_id') and not vals.get('probability'):
|
||||||
context = {}
|
|
||||||
|
|
||||||
if 'date_closed' in vals:
|
|
||||||
return super(crm_lead,self).write(cr, uid, ids, vals, context=context)
|
|
||||||
|
|
||||||
if vals.get('stage_id'):
|
|
||||||
stage = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
|
|
||||||
# change probability of lead(s) if required by stage
|
# change probability of lead(s) if required by stage
|
||||||
if not vals.get('probability') and stage.on_change:
|
stage = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
|
||||||
|
if stage.on_change:
|
||||||
vals['probability'] = stage.probability
|
vals['probability'] = stage.probability
|
||||||
for case in self.browse(cr, uid, ids, context=context):
|
|
||||||
message = _("Stage changed to <b>%s</b>.") % (stage.name)
|
|
||||||
case.message_append_note(body=message)
|
|
||||||
return super(crm_lead,self).write(cr, uid, ids, vals, context)
|
return super(crm_lead,self).write(cr, uid, ids, vals, context)
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
|
@ -877,6 +866,11 @@ class crm_lead(base_stage, osv.osv):
|
||||||
sub_ids.append(obj.user_id.id)
|
sub_ids.append(obj.user_id.id)
|
||||||
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
|
||||||
|
|
||||||
|
def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
|
||||||
|
""" Override of the (void) default notification method. """
|
||||||
|
stage_name = self.pool.get('crm.case.stage').name_get(cr, uid, [stage_id], context=context)[0][1]
|
||||||
|
return self.message_append_note(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), context=context)
|
||||||
|
|
||||||
def case_get_note_msg_prefix(self, cr, uid, lead, context=None):
|
def case_get_note_msg_prefix(self, cr, uid, lead, context=None):
|
||||||
if isinstance(lead, (int, long)):
|
if isinstance(lead, (int, long)):
|
||||||
lead = self.browse(cr, uid, [lead], context=context)[0]
|
lead = self.browse(cr, uid, [lead], context=context)[0]
|
||||||
|
|
Loading…
Reference in New Issue