From cd2135a840847f8400c4939989a65070f276dfa5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Mon, 10 Jun 2013 16:29:27 +0200
Subject: [PATCH 01/37] [IMP] [REF] crm: WIP and first attempt to remove state
field.
crm.case.section: removed state field
crm.lead: code now use probability and on_change to fetch stages related to
Won and Lost. Improved stage management. Improved a bit the demo data.
mail: improved message_track to use browse_record instead of read result. This allows
to avoid having to track fields to be able to use them in the subtype condition.
bzr revid: tde@openerp.com-20130610142927-tyxxklojv2wxw44g
---
addons/base_status/base_stage.py | 119 +++++-------
addons/crm/__openerp__.py | 6 +-
addons/crm/crm.py | 10 +-
addons/crm/crm_lead.py | 150 ++++++---------
addons/crm/crm_lead_data.xml | 78 ++++----
addons/crm/crm_lead_demo.xml | 174 ++++++++----------
addons/crm/crm_lead_view.xml | 71 ++++---
addons/crm/crm_view.xml | 2 -
addons/crm/report/crm_lead_report.py | 17 +-
addons/crm/report/crm_lead_report_view.xml | 15 +-
addons/crm/report/crm_phonecall_report.py | 17 +-
.../crm/report/crm_phonecall_report_view.xml | 10 +-
addons/crm/res_partner.py | 3 +-
addons/crm/wizard/crm_lead_to_opportunity.py | 15 +-
addons/crm/wizard/crm_merge_opportunities.py | 5 +-
addons/mail/mail_thread.py | 13 +-
16 files changed, 298 insertions(+), 407 deletions(-)
diff --git a/addons/base_status/base_stage.py b/addons/base_status/base_stage.py
index edf9db166af..6a5386b096a 100644
--- a/addons/base_status/base_stage.py
+++ b/addons/base_status/base_stage.py
@@ -22,6 +22,7 @@
from openerp.osv import fields, osv
from openerp.tools.translate import _
+
class base_stage(object):
""" Base utility mixin class for objects willing to manage their stages.
Object that inherit from this class should inherit from mailgate.thread
@@ -55,7 +56,7 @@ class base_stage(object):
if context.get('portal'):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
return user.email
- return False
+ return False
def _get_default_user(self, cr, uid, context=None):
""" Gives current user id
@@ -67,17 +68,20 @@ class base_stage(object):
return False
return uid
- def onchange_partner_address_id(self, cr, uid, ids, add, email=False, context=None):
+ def onchange_partner_address_id(self, cr, uid, ids, address_id, context=None):
""" This function returns value of partner email based on Partner Address
- :param add: Id of Partner's address
- :param email: Partner's email ID
+ :param address_id: partner_id related to the correct address
"""
- data = {'value': {'email_from': False, 'phone':False}}
- if add:
- address = self.pool.get('res.partner').browse(cr, uid, add)
+ if context is None:
+ context = {}
+ data = {'value': {'email_from': False, 'phone': False}}
+ if address_id:
+ address = self.pool.get('res.partner').browse(cr, uid, address_id, context=context)
data['value'] = {'partner_name': address and address.name or False,
'email_from': address and address.email or False,
'phone': address and address.phone or False,
+ 'mobile': address and address.mobile or False,
+ 'fax': address and address.fax or False,
'street': address and address.street or False,
'street2': address and address.street2 or False,
'city': address and address.city or False,
@@ -85,21 +89,18 @@ class base_stage(object):
'zip': address and address.zip or False,
'country_id': address.country_id and address.country_id.id or False,
}
- fields = self.fields_get(cr, uid, context=context or {})
+ model_fields = self.fields_get(cr, uid, context=context)
for key in data['value'].keys():
- if key not in fields:
+ if key not in model_fields:
del data['value'][key]
return data
- def onchange_partner_id(self, cr, uid, ids, part, email=False):
- """ This function returns value of partner address based on partner
- :param part: Partner's id
- :param email: Partner's email ID
- """
- data={}
- if part:
- addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['contact'])
- data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
+ def onchange_partner_id(self, cr, uid, ids, partner_id, email=False, context=None):
+ """ This function returns value of partner address based on partner """
+ data = {}
+ if partner_id:
+ address = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['contact'], context=context)
+ data.update(self.onchange_partner_address_id(cr, uid, ids, address['contact'], context=context)['value'])
return {'value': data}
def _get_default_section_id(self, cr, uid, context=None):
@@ -108,7 +109,8 @@ class base_stage(object):
def _get_default_stage_id(self, cr, uid, context=None):
""" Gives default stage_id """
- return self.stage_find(cr, uid, [], None, [('state', '=', 'draft')], context=context)
+ section_id = self._get_default_section_id(cr, uid, context=context)
+ return self.stage_find(cr, uid, [], section_id, [('sequence', '=', '1')], context=context)
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
""" Find stage, with a given (optional) domain on the search,
@@ -129,18 +131,6 @@ class base_stage(object):
"""
return False
- def stage_set_with_state_name(self, cr, uid, cases, state_name, context=None):
- """ Set a new stage, with a state_name instead of a stage_id
- :param cases: browse_record of cases
- """
- if isinstance(cases, (int, long)):
- cases = self.browse(cr, uid, cases, context=context)
- for case in cases:
- stage_id = self.stage_find(cr, uid, [case], None, [('state', '=', state_name)], context=context)
- if stage_id:
- self.stage_set(cr, uid, [case.id], stage_id, context=context)
- return True
-
def stage_set(self, cr, uid, ids, stage_id, context=None):
""" Set the new stage. This methods is the right method to call
when changing states. It also checks whether an onchange is
@@ -165,8 +155,7 @@ class base_stage(object):
seq = 0
if case.stage_id:
seq = case.stage_id.sequence or 0
- section_id = None
- next_stage_id = self.stage_find(cr, uid, [case], None, [('sequence', op, seq)],order, context=context)
+ next_stage_id = self.stage_find(cr, uid, [case], None, [('sequence', op, seq)], order, context=context)
if next_stage_id:
return self.stage_set(cr, uid, [case.id], next_stage_id, context=context)
return False
@@ -175,7 +164,7 @@ class base_stage(object):
""" This function computes next stage for case from its current stage
using available stage for that case type
"""
- return self.stage_change(cr, uid, ids, '>','sequence', context)
+ return self.stage_change(cr, uid, ids, '>', 'sequence', context)
def stage_previous(self, cr, uid, ids, context=None):
""" This function computes previous stage for case from its current
@@ -192,9 +181,9 @@ class base_stage(object):
if hasattr(self, '_columns'):
if self._columns.get('date_closed'):
- default.update({ 'date_closed': False, })
+ default.update({'date_closed': False})
if self._columns.get('date_open'):
- default.update({ 'date_open': False })
+ default.update({'date_open': False})
return super(base_stage, self).copy(cr, uid, id, default, context=context)
def case_escalate(self, cr, uid, ids, context=None):
@@ -211,54 +200,42 @@ class base_stage(object):
self.write(cr, uid, [case.id], data, context=context)
return True
- def case_open(self, cr, uid, ids, context=None):
- """ Opens case """
- cases = self.browse(cr, uid, ids, context=context)
- for case in cases:
- data = {'active': True}
- if not case.user_id:
- data['user_id'] = uid
- self.case_set(cr, uid, [case.id], 'open', data, context=context)
- return True
+ # def case_open(self, cr, uid, ids, context=None):
+ # """ Opens case """
+ # cases = self.browse(cr, uid, ids, context=context)
+ # for case in cases:
+ # data = {'active': True}
+ # if not case.user_id:
+ # data['user_id'] = uid
+ # self.case_set(cr, uid, [case.id], data, context=context)
+ # return True
- def case_close(self, cr, uid, ids, context=None):
- """ Closes case """
- return self.case_set(cr, uid, ids, 'done', {'active': True, 'date_closed': fields.datetime.now()}, context=context)
+ # def case_close(self, cr, uid, ids, context=None):
+ # """ Closes case """
+ # return self.case_set(cr, uid, ids, None, {'active': True, 'date_closed': fields.datetime.now()}, context=context)
- def case_cancel(self, cr, uid, ids, context=None):
- """ Cancels case """
- return self.case_set(cr, uid, ids, 'cancel', {'active': True}, context=context)
+ # def case_cancel(self, cr, uid, ids, context=None):
+ # """ Cancels case """
+ # return self.case_set(cr, uid, ids, None, {'active': True}, context=context)
- def case_pending(self, cr, uid, ids, context=None):
- """ Set case as pending """
- return self.case_set(cr, uid, ids, 'pending', {'active': True}, context=context)
+ # def case_pending(self, cr, uid, ids, context=None):
+ # """ Set case as pending """
+ # return self.case_set(cr, uid, ids, None, {'active': True}, context=context)
- def case_reset(self, cr, uid, ids, context=None):
- """ Resets case as draft """
- return self.case_set(cr, uid, ids, 'draft', {'active': True}, context=context)
+ # def case_reset(self, cr, uid, ids, context=None):
+ # """ Resets case as draft """
+ # return self.case_set(cr, uid, ids, None, {'active': True}, context=context)
- def case_set(self, cr, uid, ids, new_state_name=None, values_to_update=None, new_stage_id=None, context=None):
+ def case_set(self, cr, uid, ids, new_stage_id, values_to_update=None, context=None):
""" Generic method for setting case. This methods wraps the update
of the record.
- :params new_state_name: the new state of the record; this method
- will call ``stage_set_with_state_name``
- that will find the stage matching the
- new state, using the ``stage_find`` method.
:params new_stage_id: alternatively, you may directly give the
new stage of the record
- :params state_name: the new value of the state, such as
- 'draft' or 'close'.
:params update_values: values that will be added with the state
update when writing values to the record.
"""
- cases = self.browse(cr, uid, ids, context=context)
- # 1. update the stage
- if new_state_name:
- self.stage_set_with_state_name(cr, uid, cases, new_state_name, context=context)
- elif not (new_stage_id is None):
- self.stage_set(cr, uid, ids, new_stage_id, context=context)
- # 2. update values
+ self.stage_set(cr, uid, ids, new_stage_id, context=context)
if values_to_update:
self.write(cr, uid, ids, values_to_update, context=context)
return True
diff --git a/addons/crm/__openerp__.py b/addons/crm/__openerp__.py
index e7ab7df27ea..578eb4dce27 100644
--- a/addons/crm/__openerp__.py
+++ b/addons/crm/__openerp__.py
@@ -98,12 +98,14 @@ Dashboard for CRM will include:
'base_partner_merge_view.xml',
'crm_case_section_view.xml',
- ],
- 'demo': [
+
'crm_demo.xml',
'crm_lead_demo.xml',
'crm_phonecall_demo.xml',
'crm_action_rule_demo.xml',
+ ],
+ 'demo': [
+
],
'test': [
'test/crm_lead_message.yml',
diff --git a/addons/crm/crm.py b/addons/crm/crm.py
index 4c9a60634a5..e8bb011cdc4 100644
--- a/addons/crm/crm.py
+++ b/addons/crm/crm.py
@@ -26,7 +26,6 @@ from openerp import tools
from openerp.osv import fields
from openerp.osv import osv
-MAX_LEVEL = 15
AVAILABLE_STATES = [
('draft', 'New'),
('cancel', 'Cancelled'),
@@ -72,16 +71,13 @@ class crm_case_stage(osv.osv):
'probability': fields.float('Probability (%)', required=True, help="This percentage depicts the default/average probability of the Case for this stage to be a success"),
'on_change': fields.boolean('Change Probability Automatically', help="Setting this stage will change the probability automatically on the opportunity."),
'requirements': fields.text('Requirements'),
- 'section_ids':fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', string='Sections',
+ 'section_ids': fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', string='Sections',
help="Link between stages and sales teams. When set, this limitate the current stage to the selected sales teams."),
- 'state': fields.selection(AVAILABLE_STATES, 'Related Status', required=True,
- help="The status of your document will automatically change regarding the selected stage. " \
- "For example, if a stage is related to the status 'Close', when your document reaches this stage, it is automatically closed."),
'case_default': fields.boolean('Default to New Sales Team',
help="If you check this field, this stage will be proposed by default on each sales team. It will not assign this stage to existing teams."),
'fold': fields.boolean('Fold by Default',
help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."),
- 'type': fields.selection([ ('lead','Lead'),
+ 'type': fields.selection([('lead', 'Lead'),
('opportunity', 'Opportunity'),
('both', 'Both')],
string='Type', size=16, required=True,
@@ -91,7 +87,7 @@ class crm_case_stage(osv.osv):
_defaults = {
'sequence': lambda *args: 1,
'probability': lambda *args: 0.0,
- 'state': 'open',
+ 'on_change': True,
'fold': False,
'type': 'both',
'case_default': True,
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index b8673e73927..564b51b05c2 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -62,11 +62,7 @@ CRM_LEAD_FIELDS_TO_MERGE = ['name',
'email_from',
'email_cc',
'partner_name']
-CRM_LEAD_PENDING_STATES = (
- crm.AVAILABLE_STATES[2][0], # Cancelled
- crm.AVAILABLE_STATES[3][0], # Done
- crm.AVAILABLE_STATES[4][0], # Pending
-)
+
class crm_lead(base_stage, format_address, osv.osv):
""" CRM Lead Case """
@@ -76,14 +72,12 @@ class crm_lead(base_stage, format_address, osv.osv):
_inherit = ['mail.thread', 'ir.needaction_mixin']
_track = {
- 'state': {
- 'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['new', 'draft'],
- 'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done',
- 'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'cancel',
- },
'stage_id': {
- 'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'draft', 'cancel', 'done'],
- },
+ 'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj.probability == 0 and obj.stage_id and obj.stage_id.sequence == 1,
+ 'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj.probability > 0 and obj.probability < 100,
+ 'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj.probability == 100,
+ 'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj.probability == 0 and obj.stage_id and obj.stage_id.sequence != 1,
+ }
}
def get_empty_list_help(self, cr, uid, help, context=None):
@@ -111,11 +105,6 @@ class crm_lead(base_stage, format_address, osv.osv):
""" Gives default section by checking if present in the context """
return self._resolve_section_id_from_context(cr, uid, context=context) or False
- def _get_default_stage_id(self, cr, uid, context=None):
- """ Gives default stage_id """
- section_id = self._get_default_section_id(cr, uid, context=context)
- return self.stage_find(cr, uid, [], section_id, [('state', '=', 'draft')], context=context)
-
def _resolve_section_id_from_context(self, cr, uid, context=None):
""" Returns ID of section based on the value of 'section_id'
context key, or None if it cannot be resolved to a single
@@ -166,7 +155,7 @@ class crm_lead(base_stage, format_address, osv.osv):
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)
# restore order of the search
- result.sort(lambda x,y: cmp(stage_ids.index(x[0]), stage_ids.index(y[0])))
+ result.sort(lambda x, y: cmp(stage_ids.index(x[0]), stage_ids.index(y[0])))
fold = {}
for stage in stage_obj.browse(cr, access_rights_uid, stage_ids, context=context):
@@ -174,7 +163,7 @@ class crm_lead(base_stage, format_address, osv.osv):
return result, fold
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
- res = super(crm_lead,self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
+ res = super(crm_lead, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
res['arch'] = self.fields_view_get_address(cr, user, res['arch'], context=context)
return res
@@ -236,17 +225,6 @@ class crm_lead(base_stage, format_address, osv.osv):
res[lead.id][field] = abs(int(duration))
return res
- def _history_search(self, cr, uid, obj, name, args, context=None):
- res = []
- msg_obj = self.pool.get('mail.message')
- message_ids = msg_obj.search(cr, uid, [('email_from','!=',False), ('subject', args[0][1], args[0][2])], context=context)
- lead_ids = self.search(cr, uid, [('message_ids', 'in', message_ids)], context=context)
-
- if lead_ids:
- return [('id', 'in', lead_ids)]
- else:
- return [('id', '=', '0')]
-
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', track_visibility='onchange',
select=True, help="Linked partner (optional). Usually created when converting the lead."),
@@ -259,21 +237,21 @@ class crm_lead(base_stage, format_address, osv.osv):
'email_from': fields.char('Email', size=128, help="Email address of the contact", select=1),
'section_id': fields.many2one('crm.case.section', 'Sales Team',
select=True, track_visibility='onchange', help='When sending mails, the default email address is taken from the sales team.'),
- 'create_date': fields.datetime('Creation Date' , readonly=True),
- 'email_cc': fields.text('Global CC', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
+ 'create_date': fields.datetime('Creation Date', readonly=True),
+ 'email_cc': fields.text('Global CC', size=252, help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'description': fields.text('Notes'),
- 'write_date': fields.datetime('Update Date' , readonly=True),
+ 'write_date': fields.datetime('Update Date', readonly=True),
'categ_ids': fields.many2many('crm.case.categ', 'crm_lead_category_rel', 'lead_id', 'category_id', 'Categories', \
domain="['|',('section_id','=',section_id),('section_id','=',False), ('object_id.model', '=', 'crm.lead')]"),
'type_id': fields.many2one('crm.case.resource.type', 'Campaign', \
domain="['|',('section_id','=',section_id),('section_id','=',False)]", help="From which campaign (seminar, marketing campaign, mass mailing, ...) did this contact come from?"),
'channel_id': fields.many2one('crm.case.channel', 'Channel', help="Communication channel (mail, direct, phone, ...)"),
'contact_name': fields.char('Contact Name', size=64),
- 'partner_name': fields.char("Customer Name", size=64,help='The name of the future partner company that will be created while converting the lead into opportunity', select=1),
+ 'partner_name': fields.char("Customer Name", size=64, help='The name of the future partner company that will be created while converting the lead into opportunity', select=1),
'opt_out': fields.boolean('Opt-Out', oldname='optout',
help="If opt-out is checked, this contact has refused to receive emails for mass mailing and marketing campaign. "
"Filter 'Available for Mass Mailing' allows users to filter the leads when performing mass mailing."),
- 'type':fields.selection([ ('lead','Lead'), ('opportunity','Opportunity'), ],'Type', help="Type is used to separate Leads and Opportunities"),
+ 'type': fields.selection([('lead', 'Lead'), ('opportunity', 'Opportunity'), ], 'Type', help="Type is used to separate Leads and Opportunities"),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority', select=True),
'date_closed': fields.datetime('Closed', readonly=True),
'stage_id': fields.many2one('crm.case.stage', 'Stage', track_visibility='onchange',
@@ -285,12 +263,9 @@ class crm_lead(base_stage, format_address, osv.osv):
multi='day_open', type="float", store=True),
'day_close': fields.function(_compute_day, string='Days to Close', \
multi='day_close', type="float", store=True),
- 'state': fields.related('stage_id', 'state', type="selection", store=True,
- selection=crm.AVAILABLE_STATES, string="Status", readonly=True,
- help='The Status is set to \'Draft\', when a case is created. If the case is in progress the Status is set to \'Open\'. When the case is over, the Status is set to \'Done\'. If the case needs to be reviewed then the Status is set to \'Pending\'.'),
# Only used for type opportunity
- 'probability': fields.float('Success Rate (%)',group_operator="avg"),
+ 'probability': fields.float('Success Rate (%)', group_operator="avg"),
'planned_revenue': fields.float('Expected Revenue', track_visibility='always'),
'ref': fields.reference('Reference', selection=crm._links_get, size=128),
'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
@@ -341,30 +316,11 @@ class crm_lead(base_stage, format_address, osv.osv):
def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
if not stage_id:
- return {'value':{}}
- stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
+ return {'value': {}}
+ stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context=context)
if not stage.on_change:
- return {'value':{}}
- return {'value':{'probability': stage.probability}}
-
- def on_change_partner(self, cr, uid, ids, partner_id, context=None):
- result = {}
- values = {}
- if partner_id:
- partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
- values = {
- 'partner_name' : partner.name,
- 'street' : partner.street,
- 'street2' : partner.street2,
- 'city' : partner.city,
- 'state_id' : partner.state_id and partner.state_id.id or False,
- 'country_id' : partner.country_id and partner.country_id.id or False,
- 'email_from' : partner.email,
- 'phone' : partner.phone,
- 'mobile' : partner.mobile,
- 'fax' : partner.fax,
- }
- return {'value' : values}
+ return {'value': {}}
+ return {'value': {'probability': stage.probability}}
def on_change_user(self, cr, uid, ids, user_id, context=None):
""" When changing the user, also set a section_id or restrict section id
@@ -403,16 +359,16 @@ class crm_lead(base_stage, format_address, osv.osv):
if isinstance(cases, (int, long)):
cases = self.browse(cr, uid, cases, context=context)
# collect all section_ids
- section_ids = []
+ section_ids = set()
types = ['both']
- if not cases :
- type = context.get('default_type')
- types += [type]
+ if not cases:
+ ctx_type = context.get('default_type')
+ types += [ctx_type]
if section_id:
- section_ids.append(section_id)
+ section_ids.add(section_id)
for lead in cases:
if lead.section_id:
- section_ids.append(lead.section_id.id)
+ section_ids.add(lead.section_id.id)
if lead.type not in types:
types.append(lead.type)
# OR all section_ids and OR with case_default
@@ -421,8 +377,7 @@ class crm_lead(base_stage, format_address, osv.osv):
search_domain += [('|')] * len(section_ids)
for section_id in section_ids:
search_domain.append(('section_ids', '=', section_id))
- else:
- search_domain.append(('case_default', '=', True))
+ search_domain.append(('case_default', '=', True))
# AND with cases types
search_domain.append(('type', 'in', types))
# AND with the domain in parameter
@@ -433,38 +388,36 @@ class crm_lead(base_stage, format_address, osv.osv):
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 """
+ """ Mark the case as lost: stage with probability=0, on_change=True """
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)
+ stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0), ('on_change', '=', True), ('sequence', '>', 1)], context=context)
if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={'probability': 0.0}, new_stage_id=stage_id, context=context)
+ self.case_set(cr, uid, [lead.id], new_stage_id=stage_id, context=context)
+ else:
+ raise self.pool.get('res.config.settings').get_config_warning(cr,
+ _("To relieve your sales pipe and group all Lost opportunities, configure one of your sales stage as follow:\n"
+ "probability = 0, sequence != 1 and on_change = True.\n"
+ "You can create a specific column or edit an existing one from the menu %(menu:crm.menu_crm_case_section_act)s"), context=context)
return True
def case_mark_won(self, cr, uid, ids, context=None):
- """ Mark the case as won: state=done and probability=100 """
+ """ Mark the case as won: stage with probability=100, , on_change=True """
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)
+ stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0), ('on_change', '=', True)], context=context)
if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={'probability': 100.0}, new_stage_id=stage_id, context=context)
+ self.case_set(cr, uid, [lead.id], new_stage_id=stage_id, context=context)
+ else:
+ raise self.pool.get('res.config.settings').get_config_warning(cr,
+ _("To relieve your sales pipe and group all Won opportunities, configure one of your sales stage as follow:\n"
+ "probability = 100 and on_change = True.\n"
+ "You can create a specific column or edit an existing one from the menu %(menu:crm.menu_crm_case_section_act)s"), context=context)
return True
def set_priority(self, cr, uid, ids, priority):
""" Set lead priority
"""
- return self.write(cr, uid, ids, {'priority' : priority})
+ return self.write(cr, uid, ids, {'priority': priority})
def set_high_priority(self, cr, uid, ids, context=None):
""" Set lead priority to high
@@ -650,7 +603,7 @@ class crm_lead(base_stage, format_address, osv.osv):
sequenced_opps = []
for opportunity in opportunities:
sequence = -1
- if opportunity.stage_id and opportunity.stage_id.state != 'cancel':
+ if opportunity.stage_id:
sequence = opportunity.stage_id.sequence
sequenced_opps.append(((int(sequence != -1 and opportunity.type == 'opportunity'), sequence, -opportunity.id), opportunity))
@@ -705,8 +658,8 @@ class crm_lead(base_stage, format_address, osv.osv):
'email_from': customer and customer.email or lead.email_from,
'phone': customer and customer.phone or lead.phone,
}
- if not lead.stage_id or lead.stage_id.type=='lead':
- val['stage_id'] = self.stage_find(cr, uid, [lead], section_id, [('state', '=', 'draft'),('type', 'in', ('opportunity','both'))], context=context)
+ if not lead.stage_id or lead.stage_id.type == 'lead':
+ val['stage_id'] = self.stage_find(cr, uid, [lead], section_id, ['&', ('sequence', '=', '1'), ('type', 'in', ('opportunity', 'both'))], context=context)
return val
def convert_opportunity(self, cr, uid, ids, partner_id, user_ids=False, section_id=False, context=None):
@@ -715,7 +668,8 @@ class crm_lead(base_stage, format_address, osv.osv):
partner = self.pool.get('res.partner')
customer = partner.browse(cr, uid, partner_id, context=context)
for lead in self.browse(cr, uid, ids, context=context):
- if lead.state in ('done', 'cancel'):
+ # avoid done / cancelled leads
+ if lead.probability == 100 or (lead.probability == 0 and lead.stage_id and lead.stage_id.sequence == 1):
continue
vals = self._convert_opportunity_data(cr, uid, lead, customer, section_id, context=context)
self.write(cr, uid, [lead.id], vals, context=context)
@@ -1025,7 +979,7 @@ class crm_lead(base_stage, format_address, osv.osv):
'user_id': False,
}
if msg.get('author_id'):
- defaults.update(self.on_change_partner(cr, uid, None, msg.get('author_id'), context=context)['value'])
+ defaults.update(self.onchange_partner_id(cr, uid, None, msg.get('author_id'), context=context)['value'])
if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES):
defaults['priority'] = msg.get('priority')
defaults.update(custom_values)
@@ -1038,14 +992,14 @@ class crm_lead(base_stage, format_address, osv.osv):
"""
if isinstance(ids, (str, int, long)):
ids = [ids]
- if update_vals is None: update_vals = {}
-
+ if update_vals is None:
+ update_vals = {}
if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES):
update_vals['priority'] = msg.get('priority')
maps = {
- 'cost':'planned_cost',
+ 'cost': 'planned_cost',
'revenue': 'planned_revenue',
- 'probability':'probability',
+ 'probability': 'probability',
}
for line in msg.get('body', '').split('\n'):
line = line.strip()
diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml
index 0979a94eb3f..cda92abc72d 100644
--- a/addons/crm/crm_lead_data.xml
+++ b/addons/crm/crm_lead_data.xml
@@ -1,75 +1,61 @@
-
-
+
+
New
-
- draft
-
-
+ 1
+ 0
+ 1
+ 1
both
- Opportunity
-
- open
-
-
- lead
-
-
Dead
-
-
- cancel
-
-
+ 1
+ 0
+ 1
+ 30
lead
Qualification
-
- open
-
-
+ 1
+ 20
+ 1
+ 40
opportunity
Proposition
-
- open
-
-
+ 1
+ 40
+ 50
opportunity
Negotiation
-
- open
-
-
+ 1
+ 60
+ 60
opportunity
Won
-
-
- done
-
-
-
+ 1
+ 100
+ 1
+ 70
opportunity
-
+
Lost
-
-
-
- cancel
-
-
+ 1
+ 1
+ 0
+ 1
+ 80
opportunity
@@ -77,7 +63,7 @@
+ (4, ref('stage_lead7'))]"/>
@@ -161,7 +147,7 @@
Lead Created
crm.lead
- Opportunity created
+ Lead created
Lead to Opportunity
diff --git a/addons/crm/crm_lead_demo.xml b/addons/crm/crm_lead_demo.xml
index e7e6beae33e..cdd3b300a83 100644
--- a/addons/crm/crm_lead_demo.xml
+++ b/addons/crm/crm_lead_demo.xml
@@ -1,14 +1,15 @@
-
+
+
lead
Plan to Attend a Training
- Jason Dunagan
+ Jacques Dunagan
Le Club SARL
- jason@leclub.fr
+ jdunagan@leclub.fr
Training Manager
73, rue Léon Dierx
@@ -20,14 +21,25 @@
1
-
+
Hello,
-I am Jason from Le Club SARL.
-I am intertested to attend a training organized in your company.
-Can you send me the details ?
-
+I am Jacques from Le Club SARL.
+I am interested to attend a training organized in your company.
+Could you please send me the details ?
+
+
+
+
+
+ Inquiry
+ crm.lead
+
+ Hello,
+ I am Jacques from Le Club SARL. I am interested to attend a training organized in your company.
+ Can you send me the details ?
]]>
+ email
@@ -44,10 +56,20 @@ Can you send me the details ?
4
-
+
-
+
+
+
+
+
+ Need Details
+ crm.lead
+
+
+ Want to know features and benefits to use the new software.
+ comment
@@ -65,8 +87,10 @@ Can you send me the details ?
2
-
-
+
+
+
+
@@ -82,10 +106,12 @@ Can you send me the details ?
3
-
-
-
-
+
+
+
+
+
+
@@ -105,8 +131,8 @@ Can you send me the details ?
3
-
-
+
+
Hi,
Can you send me a quotation for 20 computers with speakers?
@@ -116,7 +142,6 @@ Purchase Manager
Stonage IT,
Franklinville
Contact: +1 813 494 5005
-
@@ -134,9 +159,8 @@ Contact: +1 813 494 5005
3
-
+
-
@@ -153,9 +177,8 @@ Contact: +1 813 494 5005
5
-
-
-
+
+
@@ -173,9 +196,8 @@ Contact: +1 813 494 5005
4
-
-
-
+
+
@@ -193,12 +215,8 @@ Contact: +1 813 494 5005
2
-
+
-
-
-
-
@@ -215,14 +233,13 @@ Contact: +1 813 494 5005
2
-
+
Hi,
I would like to know more about specification and cost of laptops of your company.
Thanks,
Andrew
-
@@ -239,9 +256,8 @@ Andrew
3
-
+
-
@@ -258,22 +274,23 @@ Andrew
2
-
-
-
+
+
-
@@ -297,7 +314,6 @@ Andrew
-
@@ -323,7 +339,6 @@ Andrew
-
@@ -344,9 +359,8 @@ Andrew
Call to ask system requirement
-
-
-
+
+
@@ -369,9 +383,8 @@ Andrew
Convert to quote
-
-
-
+
+
@@ -395,9 +408,8 @@ Andrew
Send price list regarding our interventions
-
-
-
+
+
@@ -420,7 +432,7 @@ Andrew
Call to define real needs about training
-
+
@@ -444,9 +456,8 @@ Andrew
Ask for the good receprion of the proposition
-
-
-
+
+
@@ -462,8 +473,7 @@ Andrew
2
-
-
+
@@ -477,9 +487,8 @@ Andrew
3
-
-
-
+
+
@@ -496,8 +505,7 @@ Andrew
3
-
-
+
@@ -512,9 +520,8 @@ Andrew
5
-
-
-
+
+
@@ -532,9 +539,8 @@ Andrew
-
-
-
+
+
@@ -556,8 +562,7 @@ Andrew
Conf call with technical service
-
-
+
@@ -581,9 +586,8 @@ Andrew
Send Catalogue by Email
-
-
-
+
+
@@ -689,22 +693,6 @@ Andrew
-
- Inquiry
- crm.lead
-
- Hello,
- I am Jason from Le Club SARL. I am interested to attend a training organized in your company.
- Can you send me the details ?]]>
- email
-
-
- Need Details
- crm.lead
-
- Want to know features and benefits to use the new software.
- comment
-
diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml
index 6ddd06c1c90..b5d28e583a4 100644
--- a/addons/crm/crm_lead_view.xml
+++ b/addons/crm/crm_lead_view.xml
@@ -12,9 +12,10 @@
crm.case.stage
-
-
+
+
+
@@ -94,11 +95,8 @@