- def stage_find_lost(self, cr, uid, section_id):
- return self.stage_find_percent(cr, uid, 0.0, section_id)
-
- def stage_find_won(self, cr, uid, section_id):
- return self.stage_find_percent(cr, uid, 100.0, section_id)
-
- def get_needaction_user_ids(self, cr, uid, ids, context=None):
- result = dict.fromkeys(ids, [])
- for obj in self.browse(cr, uid, ids, context=context):
- # salesman must perform an action when in draft mode
- if obj.state == 'draft' and obj.user_id:
- result[obj.id] = [obj.user_id.id]
- return result
-
- def message_get_subscribers(self, cr, uid, ids, context=None):
- sub_ids = self.message_get_subscribers_ids(cr, uid, ids, context=context)
- # add salesman to the subscribers
- for obj in self.browse(cr, uid, ids, context=context):
- if obj.user_id:
- sub_ids.append(obj.user_id.id)
- return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
-
- def create_send_note(self, cr, uid, ids, context=None):
- for id in ids:
- message = _("%s has been <b>created</b>.")% (self.case_get_note_msg_prefix(cr, uid, id, context=context))
- self.message_append_note(cr, uid, [id], _('System notification'),
- message, type='notification', context=context)
- return True
-
- def case_get_note_msg_prefix(self, cr, uid, id, context=None):
- lead = self.browse(cr, uid, [id], context=context)[0]
- return ('Opportunity' if lead.type == 'opportunity' else 'Lead')
-
- def case_mark_lost_send_note(self, cr, uid, ids, context=None):
- message = _("Opportunity has been <b>lost</b>.")
- return self.message_append_note(cr, uid, ids, message, context=context)
-
- def case_mark_won_send_note(self, cr, uid, ids, context=None):
- message = _("Opportunity has been <b>won</b>.")
- return self.message_append_note(cr, uid, ids, message, context=context)
-
- def schedule_phonecall_send_note(self, cr, uid, ids, phonecall_id, action, context=None):
- phonecall = self.pool.get('crm.phonecall').browse(cr, uid, [phonecall_id], context=context)[0]
- if action == 'log': prefix = 'Logged'
- else: prefix = 'Scheduled'
- message = _("<b>%s a call</b> for the <em>%s</em>.") % (prefix, phonecall.date)
- return self. message_append_note(cr, uid, ids, 'System Notification', message, context=context)
-
- def _lead_set_partner_send_note(self, cr, uid, ids, context=None):
- for lead in self.browse(cr, uid, ids, context=context):
- message = _("%s <b>partner</b> is now set to <em>%s</em>." % (self.case_get_note_msg_prefix(cr, uid, lead.id, context=context), lead.partner_id.name))
- lead.message_append_note('System Notification' ,message)
- return True
-
- def case_open(self, cr, uid, ids, context=None):
- for lead in self.browse(cr, uid, ids, context=context):
- if lead.state == 'draft':
- value = {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')}
- self.write(cr, uid, [lead.id], value)
- if lead.type == 'opportunity' and not lead.stage_id:
- stage_id = self.stage_find(cr, uid, lead.section_id.id or False, [('sequence','>',0)])
- if stage_id:
- self.stage_set(cr, uid, [lead.id], stage_id)
- res = super(crm_lead, self).case_open(cr, uid, ids, context)
- return res
-
- def case_close(self, cr, uid, ids, context=None):
- res = super(crm_lead, self).case_close(cr, uid, ids, context)
- self.write(cr, uid, ids, {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')})
- return res
-