return stage_ids[0]
return False
- def case_cancel(self, cr, uid, ids, context=None):
- """ Overrides case_cancel from base_stage to set probability """
- res = super(crm_lead, self).case_cancel(cr, uid, ids, context=context)
- self.write(cr, uid, ids, {'probability' : 0.0}, context=context)
- return res
-
- def case_reset(self, cr, uid, ids, context=None):
- """ Overrides case_reset from base_stage to set probability """
- res = super(crm_lead, self).case_reset(cr, uid, ids, context=context)
- self.write(cr, uid, ids, {'probability': 0.0}, context=context)
- return res
-
def case_mark_lost(self, cr, uid, ids, context=None):
- """ Mark the case as lost: state=cancel and probability=0 """
- for lead in self.browse(cr, uid, ids):
- stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0),('on_change','=',True)], context=context)
+ """ Mark the case as lost: state=cancel and probability=0
+ :deprecated: this method will be removed in OpenERP v8.
+ """
+ stages_leads = {}
+ for lead in self.browse(cr, uid, ids, context=context):
+ stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0), ('fold', '=', True), ('sequence', '>', 1)], context=context)
if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={'probability': 0.0, 'date_closed': fields.datetime.now()}, new_stage_id=stage_id, context=context)
+ if stages_leads.get(stage_id):
+ stages_leads[stage_id].append(lead.id)
+ else:
+ stages_leads[stage_id] = [lead.id]
+ else:
+ raise osv.except_osv(_('Warning!'),
+ _('To relieve your sales pipe and group all Lost opportunities, configure one of your sales stage as follow:\n'
+ 'probability = 0 %, select "Change Probability Automatically".\n'
+ 'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.'))
+ for stage_id, lead_ids in stages_leads.items():
- self.write(cr, uid, lead_ids, {'stage_id': stage_id}, context=context)
++ self.write(cr, uid, lead_ids, {'stage_id': stage_id, 'date_closed': fields.datetime.now()}, context=context)
return True
def case_mark_won(self, cr, uid, ids, context=None):
- """ Mark the case as won: state=done and probability=100 """
- for lead in self.browse(cr, uid, ids):
- stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0),('on_change','=',True)], context=context)
+ """ Mark the case as won: state=done and probability=100
+ :deprecated: this method will be removed in OpenERP v8.
+ """
+ stages_leads = {}
+ for lead in self.browse(cr, uid, ids, context=context):
+ stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0), ('fold', '=', True)], context=context)
if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={'probability': 100.0, 'date_closed': fields.datetime.now()}, new_stage_id=stage_id, context=context)
+ if stages_leads.get(stage_id):
+ stages_leads[stage_id].append(lead.id)
+ else:
+ stages_leads[stage_id] = [lead.id]
+ else:
+ raise osv.except_osv(_('Warning!'),
+ _('To relieve your sales pipe and group all Won opportunities, configure one of your sales stage as follow:\n'
+ 'probability = 100 % and select "Change Probability Automatically".\n'
+ 'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.'))
+ for stage_id, lead_ids in stages_leads.items():
- self.write(cr, uid, lead_ids, {'stage_id': stage_id}, context=context)
++ self.write(cr, uid, lead_ids, {'stage_id': stage_id, 'date_closed': fields.datetime.now()}, context=context)
+ return True
+
+ def case_escalate(self, cr, uid, ids, context=None):
+ """ Escalates case to parent level """
+ for case in self.browse(cr, uid, ids, context=context):
+ data = {'active': True}
+ if case.section_id.parent_id:
+ data['section_id'] = case.section_id.parent_id.id
+ if case.section_id.parent_id.change_responsible:
+ if case.section_id.parent_id.user_id:
+ data['user_id'] = case.section_id.parent_id.user_id.id
+ else:
+ raise osv.except_osv(_('Error!'), _("You are already at the top level of your sales-team category.\nTherefore you cannot escalate furthermore."))
+ self.write(cr, uid, [case.id], data, context=context)
return True
- def set_priority(self, cr, uid, ids, priority):
+ def set_priority(self, cr, uid, ids, priority, context=None):
""" Set lead priority
"""
- return self.write(cr, uid, ids, {'priority' : priority})
+ return self.write(cr, uid, ids, {'priority': priority}, context=context)
def set_high_priority(self, cr, uid, ids, context=None):
""" Set lead priority to high