diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index e344b0153df..af02e3be1bf 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -19,7 +19,6 @@
#
##############################################################################
-from openerp.addons.base_status.base_stage import base_stage
import crm
from datetime import datetime
from operator import itemgetter
@@ -68,7 +67,7 @@ CRM_LEAD_PENDING_STATES = (
crm.AVAILABLE_STATES[4][0], # Pending
)
-class crm_lead(base_stage, format_address, osv.osv):
+class crm_lead(format_address, osv.osv):
""" CRM Lead Case """
_name = "crm.lead"
_description = "Lead/Opportunity"
@@ -93,18 +92,6 @@ class crm_lead(base_stage, format_address, osv.osv):
context['empty_list_help_document_name'] = _("leads")
return super(crm_lead, self).get_empty_list_help(cr, uid, help, context=context)
- def create(self, cr, uid, vals, context=None):
- if context is None:
- context = {}
- if vals.get('type') and not context.get('default_type'):
- context['default_type'] = vals.get('type')
- if vals.get('section_id') and not context.get('default_section_id'):
- context['default_section_id'] = vals.get('section_id')
-
- # context: no_log, because subtype already handle this
- create_context = dict(context, mail_create_nolog=True)
- return super(crm_lead, self).create(cr, uid, vals, context=create_context)
-
def _get_default_section_id(self, cr, uid, context=None):
""" Gives default section by checking if present in the context """
return self._resolve_section_id_from_context(cr, uid, context=context) or False
@@ -124,8 +111,7 @@ class crm_lead(base_stage, format_address, osv.osv):
if type(context.get('default_section_id')) in (int, long):
return context.get('default_section_id')
if isinstance(context.get('default_section_id'), basestring):
- section_name = context['default_section_id']
- section_ids = self.pool.get('crm.case.section').name_search(cr, uid, name=section_name, context=context)
+ section_ids = self.pool.get('crm.case.section').name_search(cr, uid, name=context['default_section_id'], context=context)
if len(section_ids) == 1:
return int(section_ids[0][0])
return None
@@ -324,8 +310,7 @@ class crm_lead(base_stage, format_address, osv.osv):
_defaults = {
'active': 1,
'type': 'lead',
- 'user_id': lambda s, cr, uid, c: s._get_default_user(cr, uid, c),
- 'email_from': lambda s, cr, uid, c: s._get_default_email(cr, uid, c),
+ 'user_id': lambda s, cr, uid, c: uid,
'stage_id': lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c),
'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c),
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c),
@@ -339,30 +324,29 @@ 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':{}}
+ return {'value': {}}
stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
if not stage.on_change:
- return {'value':{}}
- return {'value':{'probability': stage.probability}}
+ return {'value': {}}
+ return {'value': {'probability': stage.probability}}
- def on_change_partner(self, cr, uid, ids, partner_id, context=None):
- result = {}
+ def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
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,
+ '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': values}
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,7 +387,7 @@ class crm_lead(base_stage, format_address, osv.osv):
# collect all section_ids
section_ids = []
types = ['both']
- if not cases :
+ if not cases:
type = context.get('default_type')
types += [type]
if section_id:
@@ -431,24 +415,18 @@ 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 stage_set(self, cr, uid, ids, stage_id, context=None):
+ """ Set the new stage. Now just writes the stage.
+ TDE TODO: remove me when removing state
+ """
+ return self.write(cr, uid, ids, {'stage_id': stage_id}, context=context)
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)
if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={'probability': 0.0}, new_stage_id=stage_id, context=context)
+ self.stage_set(cr, uid, [lead.id], stage_id, context=context)
return True
def case_mark_won(self, cr, uid, ids, context=None):
@@ -456,7 +434,21 @@ class crm_lead(base_stage, format_address, osv.osv):
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)
if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={'probability': 100.0}, new_stage_id=stage_id, context=context)
+ self.stage_set(cr, uid, [lead.id], stage_id, 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):
@@ -930,12 +922,22 @@ class crm_lead(base_stage, format_address, osv.osv):
}
return res
+ def create(self, cr, uid, vals, context=None):
+ if context is None:
+ context = {}
+ if vals.get('type') and not context.get('default_type'):
+ context['default_type'] = vals.get('type')
+ if vals.get('section_id') and not context.get('default_section_id'):
+ context['default_section_id'] = vals.get('section_id')
+
+ # context: no_log, because subtype already handle this
+ create_context = dict(context, mail_create_nolog=True)
+ return super(crm_lead, self).create(cr, uid, vals, context=create_context)
+
def write(self, cr, uid, ids, vals, context=None):
if vals.get('stage_id') and not vals.get('probability'):
- # change probability of lead(s) if required by stage
- stage = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
- if stage.on_change:
- vals['probability'] = stage.probability
+ onchange_stage_values = self.onchange_stage_id(cr, uid, ids, vals.get('stage_id'), context=context)['value']
+ vals.update(onchange_stage_values)
return super(crm_lead, self).write(cr, uid, ids, vals, context=context)
def new_mail_send(self, cr, uid, ids, context=None):
@@ -1022,7 +1024,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.on_change_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)
diff --git a/addons/crm/crm_lead_demo.xml b/addons/crm/crm_lead_demo.xml
index 4c6cf47c4f7..3917fadbd32 100644
--- a/addons/crm/crm_lead_demo.xml
+++ b/addons/crm/crm_lead_demo.xml
@@ -263,13 +263,6 @@ Andrew
-
-
-
-
-
@@ -118,7 +114,7 @@
@@ -617,7 +613,7 @@
code
if context.get('active_model') == 'crm.lead' and context.get('active_ids'):
- self.case_cancel(cr, uid, context['active_ids'], context=context)
+ self.case_mark_lost(cr, uid, context['active_ids'], context=context)
diff --git a/addons/crm/test/crm_lead_cancel.yml b/addons/crm/test/crm_lead_cancel.yml
index 8749675bf23..0f8d9ba1df9 100644
--- a/addons/crm/test/crm_lead_cancel.yml
+++ b/addons/crm/test/crm_lead_cancel.yml
@@ -4,37 +4,6 @@
!python {model: crm.lead}: |
section_id = self.pool.get('crm.case.section').create(cr, uid, {'name': "Phone Marketing", 'parent_id': ref("crm.crm_case_section_2")})
self.write(cr, uid, [ref("crm_case_1")], {'section_id': section_id})
- self.case_cancel(cr, uid, [ref("crm_case_1")])
--
- I check cancelled lead.
--
- !python {model: crm.lead}: |
- lead = self.browse(cr, uid, ref('crm_case_1'))
- assert lead.stage_id.id == ref('crm.stage_lead7'), "Stage should be 'Dead' and is %s." % (lead.stage_id.name)
- assert lead.state == 'cancel', "Opportunity is not in 'cancel' state."
- assert lead.probability == 0.0, 'Opportunity is probably wrong and should be 0.0.'
--
- I reset cancelled lead into unqualified lead.
--
- !python {model: crm.lead}: |
- self.case_reset(cr, uid, [ref("crm_case_1")])
--
- I check unqualified lead after reset.
--
- !assert {model: crm.lead, id: crm.crm_case_1, string: Lead is in draft state}:
- - state == "draft"
--
- I re-open the lead
--
- !python {model: crm.lead}: |
- self.case_open(cr, uid, [ref("crm_case_1")])
--
- I check stage and state of the re-opened lead
--
- !python {model: crm.lead}: |
- lead = self.browse(cr, uid, ref('crm.crm_case_1'))
- assert lead.stage_id.id == ref('crm.stage_lead2'), "Opportunity stage should be 'Qualification'."
- assert lead.state == 'open', "Opportunity should be in 'open' state."
-
I escalate the lead to parent team.
-
diff --git a/addons/crm/test/crm_lead_onchange.yml b/addons/crm/test/crm_lead_onchange.yml
index 9154ffdf513..45e140e890e 100644
--- a/addons/crm/test/crm_lead_onchange.yml
+++ b/addons/crm/test/crm_lead_onchange.yml
@@ -20,9 +20,4 @@
-
!record {model: crm.phonecall, id: crm_phonecall_5}:
name: 'Bad time'
- partner_id: base.res_partner_5
--
- I set the next stage to "New" for the lead.
--
- !python {model: crm.lead}: |
- self.stage_next(cr, uid, [ref("crm_case_4")], context={'stage_type': 'lead'})
+ partner_id: base.res_partner_5
\ No newline at end of file
diff --git a/addons/crm/test/lead2opportunity2win.yml b/addons/crm/test/lead2opportunity2win.yml
index 94e7149ef77..23545c61bc1 100644
--- a/addons/crm/test/lead2opportunity2win.yml
+++ b/addons/crm/test/lead2opportunity2win.yml
@@ -1,25 +1,15 @@
-
In order to test the conversion of a lead into a opportunity,
--
- I open a lead.
--
- !python {model: crm.lead}: |
- self.case_open(cr, uid, [ref("crm_case_4")])
--
- I check if the lead state is "Open".
--
- !assert {model: crm.lead, id: crm.crm_case_4, string: Lead state is Open}:
- - state == "open"
-
I convert lead into opportunity for exiting customer.
-
!python {model: crm.lead}: |
- self.convert_opportunity(cr, uid ,[ref("crm_case_4")], ref("base.res_partner_2"))
+ self.convert_opportunity(cr, uid ,[ref("crm_case_1")], ref("base.res_partner_2"))
-
I check details of converted opportunity.
-
!python {model: crm.lead}: |
- lead = self.browse(cr, uid, ref('crm_case_4'))
+ lead = self.browse(cr, uid, ref('crm_case_1'))
assert lead.type == 'opportunity', 'Lead is not converted to opportunity!'
assert lead.partner_id.id == ref("base.res_partner_2"), 'Partner mismatch!'
assert lead.stage_id.id == ref("stage_lead1"), 'Stage of opportunity is incorrect!'
@@ -28,7 +18,7 @@
-
!python {model: crm.opportunity2phonecall}: |
import time
- context.update({'active_model': 'crm.lead', 'active_ids': [ref('crm_case_4')]})
+ context.update({'active_model': 'crm.lead', 'active_ids': [ref('crm_case_1')]})
call_id = self.create(cr, uid, {'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'name': "Bonjour M. Jean, Comment allez-vous? J'ai bien reçu votre demande, pourrions-nous en parler quelques minutes?"}, context=context)
self.action_schedule(cr, uid, [call_id], context=context)
@@ -36,28 +26,28 @@
I check that phonecall is scheduled for that opportunity.
-
!python {model: crm.phonecall}: |
- ids = self.search(cr, uid, [('opportunity_id', '=', ref('crm_case_4'))])
+ ids = self.search(cr, uid, [('opportunity_id', '=', ref('crm_case_1'))])
assert len(ids), 'Phonecall is not scheduled'
-
Now I schedule meeting with customer.
-
!python {model: crm.lead}: |
- self.action_makeMeeting(cr, uid, [ref('crm_case_4')])
+ self.action_makeMeeting(cr, uid, [ref('crm_case_1')])
-
After communicated with customer, I put some notes with contract details.
-
!python {model: crm.lead}: |
- self.message_post(cr, uid, [ref('crm_case_4')], subject='Test note', body='Détails envoyés par le client sur le FAX pour la qualité')
+ self.message_post(cr, uid, [ref('crm_case_1')], subject='Test note', body='Détails envoyés par le client sur le FAX pour la qualité')
-
I win this opportunity
-
!python {model: crm.lead}: |
- self.case_mark_won(cr, uid, [ref("crm_case_4")])
+ self.case_mark_won(cr, uid, [ref("crm_case_1")])
-
I check details of the opportunity after having won the opportunity.
-
!python {model: crm.lead}: |
- lead = self.browse(cr, uid, ref('crm_case_4'))
+ lead = self.browse(cr, uid, ref('crm_case_1'))
assert lead.stage_id.id == ref('crm.stage_lead6'), "Opportunity stage should be 'Won'."
assert lead.state == 'done', "Opportunity is not in 'done' state!"
assert lead.probability == 100.0, "Revenue probability should be 100.0!"
@@ -104,7 +94,6 @@
-
!python {model: crm.meeting}: |
context.update({'active_model': 'crm.meeting'})
- self.case_open(cr, uid, [ref('base_calendar.crm_meeting_4')])
-
I invite a user for meeting.
-
diff --git a/addons/crm_claim/crm_claim.py b/addons/crm_claim/crm_claim.py
index 774571b0314..1e3ed2faad1 100644
--- a/addons/crm_claim/crm_claim.py
+++ b/addons/crm_claim/crm_claim.py
@@ -19,20 +19,12 @@
#
##############################################################################
-from openerp.addons.base_status.base_stage import base_stage
-import binascii
from openerp.addons.crm import crm
from openerp.osv import fields, osv
-import time
from openerp import tools
from openerp.tools.translate import _
from openerp.tools import html2plaintext
-CRM_CLAIM_PENDING_STATES = (
- crm.AVAILABLE_STATES[2][0], # Cancelled
- crm.AVAILABLE_STATES[3][0], # Done
- crm.AVAILABLE_STATES[4][0], # Pending
-)
class crm_claim_stage(osv.osv):
""" Model for claim stages. This models the main stages of a claim
@@ -51,8 +43,6 @@ class crm_claim_stage(osv.osv):
'section_ids':fields.many2many('crm.case.section', 'section_claim_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(crm.AVAILABLE_STATES, 'Status', required=True, help="The related status for the stage. 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 will be automatically have the 'closed' status."),
- 'case_refused': fields.boolean('Refused stage',
- help='Refused stages are specific stages for done.'),
'case_default': fields.boolean('Common to All Teams',
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('Hide in Views when Empty',
@@ -63,10 +53,9 @@ class crm_claim_stage(osv.osv):
'sequence': lambda *args: 1,
'state': 'draft',
'fold': False,
- 'case_refused': False,
}
-class crm_claim(base_stage, osv.osv):
+class crm_claim(osv.osv):
""" Crm claim
"""
_name = "crm.claim"
@@ -74,6 +63,15 @@ class crm_claim(base_stage, osv.osv):
_order = "priority,date desc"
_inherit = ['mail.thread']
+ def _get_default_section_id(self, cr, uid, context=None):
+ """ Gives default section by checking if present in the context """
+ return self.pool.get('crm.lead')._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)
+
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Claim Subject', size=128, required=True),
@@ -117,15 +115,13 @@ class crm_claim(base_stage, osv.osv):
}
_defaults = {
- 'user_id': lambda s, cr, uid, c: s._get_default_user(cr, uid, c),
- 'partner_id': lambda s, cr, uid, c: s._get_default_partner(cr, uid, c),
- 'email_from': lambda s, cr, uid, c: s._get_default_email(cr, uid, c),
+ 'user_id': lambda s, cr, uid, c: uid,
'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c),
- 'date': fields.datetime.now,
+ 'date': fields.datetime.now(),
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
'active': lambda *a: 1,
- 'stage_id':lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c)
+ 'stage_id': lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c)
}
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
@@ -158,27 +154,24 @@ class crm_claim(base_stage, osv.osv):
return stage_ids[0]
return False
- def case_refuse(self, cr, uid, ids, context=None):
- """ Mark the case as refused: state=done and case_refused=True """
- for lead in self.browse(cr, uid, ids):
- stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, ['&', ('state', '=', 'done'), ('case_refused', '=', True)], context=context)
- if stage_id:
- self.case_set(cr, uid, [lead.id], values_to_update={}, new_stage_id=stage_id, context=context)
- return True
-
- def onchange_partner_id(self, cr, uid, ids, part, email=False):
+ def onchange_partner_id(self, cr, uid, ids, partner_id, email=False, context=None):
"""This function returns value of partner address based on partner
- :param part: Partner's id
:param email: ignored
"""
- if not part:
- return {'value': {'email_from': False,
- 'partner_phone': False
- }
- }
- address = self.pool.get('res.partner').browse(cr, uid, part)
+ if not partner_id:
+ return {'value': {'email_from': False, 'partner_phone': False}}
+ address = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
return {'value': {'email_from': address.email, 'partner_phone': address.phone}}
+ def create(self, cr, uid, vals, context=None):
+ if context is None:
+ context = {}
+ if vals.get('section_id') and not context.get('default_section_id'):
+ context['default_section_id'] = vals.get('section_id')
+
+ # context: no_log, because subtype already handle this
+ return super(crm_claim, self).create(cr, uid, vals, context=context)
+
# -------------------------------------------------------
# Mail gateway
# -------------------------------------------------------
diff --git a/addons/crm_claim/crm_claim_view.xml b/addons/crm_claim/crm_claim_view.xml
index 0d2d8b391e7..28d0f7c731c 100644
--- a/addons/crm_claim/crm_claim_view.xml
+++ b/addons/crm_claim/crm_claim_view.xml
@@ -52,7 +52,6 @@
-
@@ -102,10 +101,6 @@