diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index b8673e73927..44ada2ffcc0 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -719,7 +719,6 @@ class crm_lead(base_stage, format_address, osv.osv):
continue
vals = self._convert_opportunity_data(cr, uid, lead, customer, section_id, context=context)
self.write(cr, uid, [lead.id], vals, context=context)
- self.message_post(cr, uid, ids, body=_("Lead converted into an Opportunity "), subtype="crm.mt_lead_convert_to_opportunity", context=context)
if user_ids or section_id:
self.allocate_salesman(cr, uid, ids, user_ids, section_id, context=context)
diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml
index 0979a94eb3f..92914542d9d 100644
--- a/addons/crm/crm_lead_data.xml
+++ b/addons/crm/crm_lead_data.xml
@@ -163,12 +163,6 @@
Opportunity created
-
- Lead to Opportunity
- crm.lead
-
- Lead converted into an opportunity
-
Stage Changed
crm.lead
@@ -195,13 +189,6 @@
section_id
-
- Lead to Opportunity
-
- crm.case.section
-
- section_id
-
Opportunity Stage Changed
crm.case.section
diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml
index 6ddd06c1c90..df6a4a07a8e 100644
--- a/addons/crm/crm_lead_view.xml
+++ b/addons/crm/crm_lead_view.xml
@@ -601,7 +601,9 @@
'default_email_to':'{$object.email or \'\'}',
'default_use_template': True,
'default_template_id': ref('crm.email_template_opportunity_mail'),
- }"/>
+ }"
+ groups="base.group_sale_salesman"
+ />
@@ -617,6 +619,7 @@
if context.get('active_model') == 'crm.lead' and context.get('active_ids'):
self.case_cancel(cr, uid, context['active_ids'], context=context)
+
diff --git a/addons/crm/wizard/crm_lead_to_opportunity_view.xml b/addons/crm/wizard/crm_lead_to_opportunity_view.xml
index 4093df910d0..9ddd1fc701f 100644
--- a/addons/crm/wizard/crm_lead_to_opportunity_view.xml
+++ b/addons/crm/wizard/crm_lead_to_opportunity_view.xml
@@ -102,7 +102,9 @@
res_model="crm.lead2opportunity.partner.mass" src_model="crm.lead"
view_mode="form" target="new" view_type="form"
context="{'mass_convert' : True}"
- view_id="view_crm_lead2opportunity_partner_mass"/>
+ view_id="view_crm_lead2opportunity_partner_mass"
+ groups="base.group_sale_salesman"
+ />
diff --git a/addons/crm/wizard/crm_merge_opportunities_view.xml b/addons/crm/wizard/crm_merge_opportunities_view.xml
index 919d83cb9a7..60693c13e19 100644
--- a/addons/crm/wizard/crm_merge_opportunities_view.xml
+++ b/addons/crm/wizard/crm_merge_opportunities_view.xml
@@ -45,7 +45,9 @@
multi="True"
key2="client_action_multi" name="Merge leads/opportunities"
res_model="crm.merge.opportunity" src_model="crm.lead"
- view_mode="form" target="new" view_type="form"/>
+ view_mode="form" target="new" view_type="form"
+ groups="base.group_sale_salesman"
+ />
diff --git a/addons/crm_partner_assign/__init__.py b/addons/crm_partner_assign/__init__.py
index bb4a3bb53be..6b1315cef07 100644
--- a/addons/crm_partner_assign/__init__.py
+++ b/addons/crm_partner_assign/__init__.py
@@ -20,6 +20,7 @@
##############################################################################
import crm_partner_assign
+import crm_lead
import wizard
import report
diff --git a/addons/crm_partner_assign/__openerp__.py b/addons/crm_partner_assign/__openerp__.py
index b9b21ca7a6a..37a8c5a3d6b 100644
--- a/addons/crm_partner_assign/__openerp__.py
+++ b/addons/crm_partner_assign/__openerp__.py
@@ -37,17 +37,23 @@ The most appropriate partner can be assigned.
You can also use the geolocalization without using the GPS coordinates.
""",
'author': 'OpenERP SA',
- 'depends': ['crm', 'account'],
+ 'depends': ['crm', 'account', 'portal'],
'demo': ['res_partner_demo.xml'],
'data': [
'security/ir.model.access.csv',
'res_partner_view.xml',
'wizard/crm_forward_to_partner_view.xml',
+ 'wizard/crm_channel_interested_view.xml',
'crm_lead_view.xml',
'crm_partner_assign_data.xml',
+ 'crm_portal_view.xml',
+ 'portal_data.xml',
'report/crm_lead_report_view.xml',
'report/crm_partner_report_view.xml',
],
+ 'js': [
+ 'static/src/js/next.js',
+ ],
'test': ['test/partner_assign.yml'],
'installable': True,
'auto_install': False,
diff --git a/addons/crm_partner_assign/crm_lead.py b/addons/crm_partner_assign/crm_lead.py
new file mode 100644
index 00000000000..37f4b9aedff
--- /dev/null
+++ b/addons/crm_partner_assign/crm_lead.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp.osv import osv
+from openerp.tools.translate import _
+
+
+class crm_lead(osv.osv):
+ _inherit = 'crm.lead'
+
+ def get_interested_action(self, cr, uid, interested, context=None):
+ try:
+ model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', 'crm_lead_channel_interested_act')
+ except ValueError:
+ raise osv.except_osv(_('Error!'), _("The CRM Channel Interested Action is missing"))
+ action = self.pool[model].read(cr, uid, action_id, context=context)
+ action_context = eval(action['context'])
+ action_context['interested'] = interested
+ action['context'] = str(action_context)
+ return action
+
+ def case_interested(self, cr, uid, ids, context=None):
+ return self.get_interested_action(cr, uid, True, context=context)
+
+ def case_disinterested(self, cr, uid, ids, context=None):
+ return self.get_interested_action(cr, uid, False, context=context)
diff --git a/addons/crm_partner_assign/crm_lead_view.xml b/addons/crm_partner_assign/crm_lead_view.xml
index 0d2837d6ca5..5c14680ee78 100644
--- a/addons/crm_partner_assign/crm_lead_view.xml
+++ b/addons/crm_partner_assign/crm_lead_view.xml
@@ -8,27 +8,33 @@
-
+
-
-
-
+
+
+
+
+ (
+
+ N
+ S
+
+ E
+ W
+ )
+
+
+
+
-
-
+ type="action"
+ context="{'default_composition_mode': 'forward','hide_forward_type': 1 , 'default_partner_ids': [partner_assigned_id]}"/>
-
-
-
-
-
-
@@ -43,7 +49,7 @@
-
+
@@ -55,41 +61,46 @@
-
-
+
-
+
crm.lead.lead.geo_assign.inherit
crm.lead
-
+
-
-
-
+
+
-
-
+ (
+
+ N
+ S
+
+ E
+ W
+ )
+
+
+
+
+
+
+ type="action"
+ context="{'default_composition_mode': 'forward','hide_forward_type': 1 , 'default_partner_ids': [partner_assigned_id]}"/>
-
-
-
-
-
-
@@ -104,7 +115,7 @@
-
+
@@ -116,12 +127,11 @@
-
-
+
diff --git a/addons/crm_partner_assign/crm_partner_assign.py b/addons/crm_partner_assign/crm_partner_assign.py
index b13a75a2591..daf3d844fe6 100644
--- a/addons/crm_partner_assign/crm_partner_assign.py
+++ b/addons/crm_partner_assign/crm_partner_assign.py
@@ -66,10 +66,13 @@ class res_partner_grade(osv.osv):
_columns = {
'sequence': fields.integer('Sequence'),
'active': fields.boolean('Active'),
- 'name': fields.char('Grade Name', size=32)
+ 'name': fields.char('Grade Name', size=32),
+ 'partner_weight': fields.integer('Grade Weight',
+ help="Gives the probability to assign a lead to this partner. (0 means no assignation.)"),
}
_defaults = {
- 'active': lambda *args: 1
+ 'active': lambda *args: 1,
+ 'partner_weight':1
}
class res_partner_activation(osv.osv):
@@ -88,11 +91,11 @@ class res_partner(osv.osv):
'partner_latitude': fields.float('Geo Latitude'),
'partner_longitude': fields.float('Geo Longitude'),
'date_localization': fields.date('Geo Localization Date'),
- 'partner_weight': fields.integer('Weight',
+ 'partner_weight': fields.integer('Grade Weight',
help="Gives the probability to assign a lead to this partner. (0 means no assignation.)"),
'opportunity_assigned_ids': fields.one2many('crm.lead', 'partner_assigned_id',\
'Assigned Opportunities'),
- 'grade_id': fields.many2one('res.partner.grade', 'Partner Level'),
+ 'grade_id': fields.many2one('res.partner.grade', 'Grade'),
'activation' : fields.many2one('res.partner.activation', 'Activation', select=1),
'date_partnership' : fields.date('Partnership Date'),
'date_review' : fields.date('Latest Partner Review'),
@@ -101,6 +104,13 @@ class res_partner(osv.osv):
_defaults = {
'partner_weight': lambda *args: 0
}
+
+ def onchange_grade_id(self, cr, uid, ids, grade_id, context=None):
+ res = {'value' :{'partner_weight':0}}
+ if grade_id:
+ partner_grade = self.pool.get('res.partner.grade').browse(cr, uid, grade_id)
+ res['value']['partner_weight'] = partner_grade.partner_weight
+ return res
def geo_localize(self, cr, uid, ids, context=None):
# Don't pass context to browse()! We need country names in english below
for partner in self.browse(cr, uid, ids):
@@ -124,7 +134,7 @@ class crm_lead(osv.osv):
_columns = {
'partner_latitude': fields.float('Geo Latitude'),
'partner_longitude': fields.float('Geo Longitude'),
- 'partner_assigned_id': fields.many2one('res.partner', 'Assigned Partner', help="Partner this case has been forwarded/assigned to.", select=True),
+ 'partner_assigned_id': fields.many2one('res.partner', 'Assigned Partner',track_visibility='onchange' , help="Partner this case has been forwarded/assigned to.", select=True),
'date_assign': fields.date('Assignation Date', help="Last date this case was forwarded/assigned to a partner"),
}
def _merge_data(self, cr, uid, ids, oldest, fields, context=None):
@@ -134,6 +144,7 @@ class crm_lead(osv.osv):
def onchange_assign_id(self, cr, uid, ids, partner_assigned_id, context=None):
"""This function updates the "assignation date" automatically, when manually assign a partner in the geo assign tab
"""
+
if not partner_assigned_id:
return {'value':{'date_assign': False}}
else:
@@ -261,4 +272,3 @@ class crm_lead(osv.osv):
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/crm_partner_assign/crm_partner_assign_data.xml b/addons/crm_partner_assign/crm_partner_assign_data.xml
index dab50192641..b4347b1621b 100644
--- a/addons/crm_partner_assign/crm_partner_assign_data.xml
+++ b/addons/crm_partner_assign/crm_partner_assign_data.xml
@@ -1,44 +1,59 @@
-
+
-
- Lead forward
-
- Fwd: Lead: ${object.name}
-
-
-
+
+ Assigned
+
+
+
+ lead
+
+
+ To Recycle
+
+
+
+ lead
+
+
+ Lead Mass Mail
+
+ ${ctx['partner_id'].email}
+ ${user.email or ''}
+ Fwd: Lead: ${ctx['partner_id'].name}
-Here is a lead that might interest you.
-
-
-Please keep me informed about your actions about it so that I can keep an
-accurate follow-up of it and help you in the sale cycle.
-
-
-Your account manager,
-${object.user_id.name},
-${object.user_id.email}
-
+
+Hello,
-
-${ctx["mail_body"].replace('\n',' ') | safe}
-
-% if ctx["history_mode"] in ('whole'):
- % for message in object.message_ids:
- ---- Original Message (${message.date or ''}) ----
- ${message.body | safe}
- % endfor
+We have been contacted by those prospects that are in your region. Thus, the following leads have been assigned to ${ctx['partner_id'].name}:
+
+
+% for lead in ctx['partner_leads']:
+ ${lead.lead_id.name or 'Subject Undefined'} , ${lead.lead_id.contact_name or 'Contact Name Undefined'}, ${lead.lead_id.country_id and lead.lead_id.country_id.name or 'Country Undefined' }, ${lead.lead_id.email_from or 'Email Undefined'}, ${lead.lead_id.phone or ''}
+% endfor
+
+
+% if ctx.get('partner_in_portal'):
+Please connect to your Partner Portal to get details. On each lead are two buttons on the top left corner that you should press after having contacted the lead: "I'm interested" & "I'm not interested".
+% else:
+
+ You do not have yet a portal access to our database. Please contact
+ ${ctx['partner_id'].user_id and ctx['partner_id'].user_id.email and 'your account manager %s (%s)' % (ctx['partner_id'].user_id.name,ctx['partner_id'].user_id.email) or 'us'}.
+
% endif
-% if ctx['history_mode'] == 'latest':
- ---- Original Message (${object.message_ids[0].date or ''}) ----
- ${object.message_ids[0].body | safe}
+The lead will be sent to another partner if you do not contact the lead before 20 days.
+
+Thanks,
+
+
+${ctx['partner_id'].user_id and ctx['partner_id'].user_id.signature or ''}
+
+% if not ctx['partner_id'].user_id:
+PS: It looks like you do not have an account manager assigned to you, please contact us.
% endif
]]>
-
+
\ No newline at end of file
diff --git a/addons/crm_partner_assign/crm_portal_view.xml b/addons/crm_partner_assign/crm_portal_view.xml
new file mode 100644
index 00000000000..a8d342ebb94
--- /dev/null
+++ b/addons/crm_partner_assign/crm_portal_view.xml
@@ -0,0 +1,209 @@
+
+
+
+
+ partner lead
+ crm.lead
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ crm_portal_form
+ crm.lead
+
+
+
+
+
+
+
+ partner lead
+ crm.lead
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ crm_portal_form
+ crm.lead
+
+
+
+
+
+
+
+
+
+
+ Leads
+ crm.lead
+ tree,form
+
+ [('type','like','lead')]
+
+
+
+
+ tree
+
+
+
+
+
+
+ form
+
+
+
+
+
+
+
+ Opportunities
+ crm.lead
+ tree,form
+
+ [('type','like','opportunity')]
+
+
+
+
+ tree
+
+
+
+
+
+
+ form
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/crm_partner_assign/portal_data.xml b/addons/crm_partner_assign/portal_data.xml
new file mode 100644
index 00000000000..0d4a5b30abd
--- /dev/null
+++ b/addons/crm_partner_assign/portal_data.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+ openerp.portal.res.partner
+
+
+
+
+
+
+
+
+ openerp.portal.res.partner
+
+
+ [('id','child_of',user.commercial_partner_id.id)]
+
+
+ openerp.portal.res.partner.grade
+
+
+
+
+
+
+
+
+
+
+ openerp.portal.crm.lead
+
+
+ [('partner_assigned_id','child_of',user.commercial_partner_id.id)]
+
+
+ openerp.portal.crm.lead
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/crm_partner_assign/res_partner_view.xml b/addons/crm_partner_assign/res_partner_view.xml
index 9e70835a3f1..874d2a9f053 100644
--- a/addons/crm_partner_assign/res_partner_view.xml
+++ b/addons/crm_partner_assign/res_partner_view.xml
@@ -2,7 +2,7 @@
-
+
openerp_custom.res.partner.activation.form
@@ -33,145 +33,134 @@
tree,form
-
+
-
+
-
-
- res.partner.grade.tree
- res.partner.grade
-
-
-
-
-
-
-
-
- res.partner.grade.form
- res.partner.grade
-
-
-
-
-
- Partner Grade
- res.partner.grade
- form
-
-
-
-
-
- res.partner.geo.inherit.tree
- res.partner
-
-
-
-
-
-
+
+ res.partner.grade.tree
+ res.partner.grade
+
+
+
+
+
-
-
-
-
- res.partner.geo.inherit.search
- res.partner
-
-
-
-
-
-
-
-
-
-
-
-
- res.partner.geo.inherit
- res.partner
-
-
-
-
-
+
+
+ res.partner.grade.form
+ res.partner.grade
+
+
+
+
+
+ Partner Grade
+ res.partner.grade
+ form
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ res.partner.geo.inherit.tree
+ res.partner
+
+
+
+
+
+
+
+
+
+
+ res.partner.geo.inherit.search
+ res.partner
+
+
+
+
+
+
+
+
+
+
+
+
+ res.partner.geo.inherit
+ res.partner
+
+
+
+
+
+
+
+
+
+ (
+
+ N
+ S
+
+ E
+ W
+ )
+
+
+
+
+
+
+
+ Higher is the value, higher is the probability for this partner to get more leads.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/crm_partner_assign/security/ir.model.access.csv b/addons/crm_partner_assign/security/ir.model.access.csv
index 69b74ef6b3d..81d74bf43e3 100644
--- a/addons/crm_partner_assign/security/ir.model.access.csv
+++ b/addons/crm_partner_assign/security/ir.model.access.csv
@@ -5,3 +5,4 @@ access_crm_partner_report,crm.partner.report.assign.all,model_crm_partner_report
access_res_partner_grade,res.partner.grade,model_res_partner_grade,base.group_sale_salesman,1,1,1,0
access_res_partner_grade_manager,res.partner.grade.manager,model_res_partner_grade,base.group_sale_manager,1,1,1,1
"access_partner_activation_manager","res.partner.activation.manager","model_res_partner_activation","base.group_partner_manager",1,1,1,1
+partner_access_crm_lead,crm.lead,model_crm_lead,portal.group_portal,1,1,0,0
\ No newline at end of file
diff --git a/addons/crm_partner_assign/static/src/js/next.js b/addons/crm_partner_assign/static/src/js/next.js
new file mode 100644
index 00000000000..c40f104d6c6
--- /dev/null
+++ b/addons/crm_partner_assign/static/src/js/next.js
@@ -0,0 +1,13 @@
+openerp.crm_partner_assign = function (instance) {
+ instance.crm_partner_assign = instance.crm_partner_assign || {};
+ instance.crm_partner_assign.next_or_list = function(parent) {
+ var form = parent.inner_widget.views.form.controller;
+ form.dataset.remove_ids([form.dataset.ids[form.dataset.index]]);
+ form.reload();
+ if (!form.dataset.ids.length){
+ parent.inner_widget.switch_mode('list');
+ }
+ parent.do_action({ type: 'ir.actions.act_window_close' });
+ };
+ instance.web.client_actions.add("next_or_list", "instance.crm_partner_assign.next_or_list");
+}
\ No newline at end of file
diff --git a/addons/crm_partner_assign/wizard/__init__.py b/addons/crm_partner_assign/wizard/__init__.py
index 9224173145b..ab6c7b7f06a 100644
--- a/addons/crm_partner_assign/wizard/__init__.py
+++ b/addons/crm_partner_assign/wizard/__init__.py
@@ -20,3 +20,4 @@
##############################################################################
import crm_forward_to_partner
+import crm_channel_interested
\ No newline at end of file
diff --git a/addons/crm_partner_assign/wizard/crm_channel_interested.py b/addons/crm_partner_assign/wizard/crm_channel_interested.py
new file mode 100644
index 00000000000..57db36cb51f
--- /dev/null
+++ b/addons/crm_partner_assign/wizard/crm_channel_interested.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (). All Rights Reserved
+# $Id$
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
+from openerp import SUPERUSER_ID
+
+
+class crm_lead_forward_to_partner(osv.TransientModel):
+ """ Forward info history to partners. """
+ _name = 'crm.lead.channel.interested'
+ _columns = {
+ 'interested': fields.boolean('Interested by this lead'),
+ 'contacted': fields.boolean('Did you contact the lead?', help="The lead has been contacted"),
+ 'comment': fields.text('Comment', help="What are the elements that have led to this decision?", required=True),
+ }
+ _defaults = {
+ 'interested': lambda self, cr, uid, c: c.get('interested', True),
+ 'contacted': False,
+ }
+
+ def action_confirm(self, cr, uid, ids, context=None):
+ wizard = self.browse(cr, uid, ids[0], context=context)
+ if wizard.interested and not wizard.contacted:
+ raise osv.except_osv(_('Error!'), _("You must contact the lead before saying that you are interested"))
+ lead_obj = self.pool.get('crm.lead')
+ lead_obj.check_access_rights(cr, uid, 'write')
+ if wizard.interested:
+ message = _('I am interested by this lead.
')
+ values = {}
+ else:
+ stage = 'stage_portal_lead_recycle'
+ message = _('I am not interested by this lead. I %scontacted the lead.
') % (not wizard.contacted and 'have not ' or '')
+ values = {'partner_assigned_id': False}
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+ partner_ids = self.pool.get('res.partner').search(cr, SUPERUSER_ID, [('id', 'child_of', user.partner_id.commercial_partner_id.id)], context=context)
+ lead_obj.message_unsubscribe(cr, SUPERUSER_ID, context.get('active_ids'), partner_ids, context=None)
+ try:
+ stage_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', stage)[1]
+ except ValueError:
+ stage_id = False
+ if stage_id:
+ values.update({'stage_id': stage_id})
+ if wizard.comment:
+ message += '%s
' % wizard.comment
+ lead_obj.message_post(cr, uid, context.get('active_ids'), body=message, context=context)
+ if values:
+ lead_obj.write(cr, SUPERUSER_ID, context.get('active_ids'), values)
+ if wizard.interested:
+ for lead in lead_obj.browse(cr, uid, context.get('active_ids'), context=context):
+ lead_obj.convert_opportunity(cr, SUPERUSER_ID, [lead.id], lead.partner_id and lead.partner_id.id or None, context=None)
+ return {
+ 'type': 'ir.actions.client',
+ 'tag': 'next_or_list',
+ 'params': {
+ },
+ }
diff --git a/addons/crm_partner_assign/wizard/crm_channel_interested_view.xml b/addons/crm_partner_assign/wizard/crm_channel_interested_view.xml
new file mode 100644
index 00000000000..400e02cd48a
--- /dev/null
+++ b/addons/crm_partner_assign/wizard/crm_channel_interested_view.xml
@@ -0,0 +1,45 @@
+
+
+
+
+ crm_lead_channel_interested
+ crm.lead.channel.interested
+
+
+
+
+
+ Lead Feedback
+ crm.lead.channel.interested
+ form
+ form
+
+ new
+
+
+
\ No newline at end of file
diff --git a/addons/crm_partner_assign/wizard/crm_forward_to_partner.py b/addons/crm_partner_assign/wizard/crm_forward_to_partner.py
index 724102a84b1..80fa2f28b04 100644
--- a/addons/crm_partner_assign/wizard/crm_forward_to_partner.py
+++ b/addons/crm_partner_assign/wizard/crm_forward_to_partner.py
@@ -27,107 +27,182 @@ from openerp.tools.translate import _
class crm_lead_forward_to_partner(osv.TransientModel):
""" Forward info history to partners. """
_name = 'crm.lead.forward.to.partner'
- _inherit = "mail.compose.message"
- def _get_composition_mode_selection(self, cr, uid, context=None):
- composition_mode = super(crm_lead_forward_to_partner, self)._get_composition_mode_selection(cr, uid, context=context)
- composition_mode.append(('forward', 'Forward'))
- return composition_mode
-
- _columns = {
- 'partner_ids': fields.many2many('res.partner',
- 'lead_forward_to_partner_res_partner_rel',
- 'wizard_id', 'partner_id', 'Additional contacts'),
- 'attachment_ids': fields.many2many('ir.attachment',
- 'lead_forward_to_partner_attachment_rel',
- 'wizard_id', 'attachment_id', 'Attachments'),
- 'history_mode': fields.selection([('info', 'Internal notes'),
- ('latest', 'Latest email'), ('whole', 'Whole Story')],
- 'Send history', required=True),
- }
-
- _defaults = {
- 'history_mode': 'info',
- }
+ def _convert_to_assignation_line(self, cr, uid, lead, partner, context=None):
+ lead_location = []
+ partner_location = []
+ if lead.country_id:
+ lead_location.append(lead.country_id.name)
+ if lead.city:
+ lead_location.append(lead.city)
+ if partner:
+ if partner.country_id:
+ partner_location.append(partner.country_id.name)
+ if partner.city:
+ partner_location.append(partner.city)
+ return {'lead_id': lead.id,
+ 'lead_location': ", ".join(lead_location),
+ 'partner_assigned_id': partner and partner.id or False,
+ 'partner_location': ", ".join(partner_location),
+ 'lead_link': self.get_lead_portal_url(cr, uid, lead.id, lead.type, context=context),
+ }
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
- # set as comment, perform overrided document-like action that calls get_record_data
- old_mode = context.get('default_composition_mode', 'forward')
- context['default_composition_mode'] = 'comment'
+ lead_obj = self.pool.get('crm.lead')
+ email_template_obj = self.pool.get('email.template')
+ try:
+ template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', 'email_template_lead_forward_mail')[1]
+ except ValueError:
+ template_id = False
res = super(crm_lead_forward_to_partner, self).default_get(cr, uid, fields, context=context)
- # back to forward mode
- context['default_composition_mode'] = old_mode
- res['composition_mode'] = context['default_composition_mode']
+ active_ids = context.get('active_ids')
+ default_composition_mode = context.get('default_composition_mode')
+ res['assignation_lines'] = []
+ if template_id:
+ res['body'] = email_template_obj.get_email_template(cr, uid, template_id).body_html
+ if active_ids:
+ lead_ids = lead_obj.browse(cr, uid, active_ids, context=context)
+ if default_composition_mode == 'mass_mail':
+ partner_assigned_ids = lead_obj.search_geo_partner(cr, uid, active_ids, context=context)
+ else:
+ partner_assigned_ids = dict((lead.id, lead.partner_assigned_id and lead.partner_assigned_id.id or False) for lead in lead_ids)
+ res['partner_id'] = lead_ids[0].partner_assigned_id.id
+ for lead in lead_ids:
+ partner_id = partner_assigned_ids.get(lead.id) or False
+ partner = False
+ if partner_id:
+ partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
+ res['assignation_lines'].append(self._convert_to_assignation_line(cr, uid, lead, partner))
return res
- def get_record_data(self, cr, uid, model, res_id, context=None):
- """ Override of mail.compose.message, to add default values coming
- form the related lead.
- """
- if context is None:
- context = {}
- res = super(crm_lead_forward_to_partner, self).get_record_data(cr, uid, model, res_id, context=context)
- if model not in ('crm.lead') or not res_id:
- return res
- template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', 'crm_partner_assign_email_template')[1]
- context['history_mode'] = context.get('history_mode','whole')
- mail_body_fields = ['partner_id', 'partner_name', 'title', 'function', 'street', 'street2', 'zip', 'city', 'country_id', 'state_id', 'email_from', 'phone', 'fax', 'mobile', 'description']
- lead = self.pool.get('crm.lead').browse(cr, uid, res_id, context=context)
- context['mail_body'] = self.pool.get('crm.lead')._mail_body(cr, uid, lead, mail_body_fields, context=context)
- template = self.generate_email_for_composer(cr, uid, template_id, res_id, context)
- res['subject'] = template['subject']
- res['body'] = template['body']
- return res
-
- def on_change_history_mode(self, cr, uid, ids, history_mode, model, res_id, context=None):
- """ Update body when changing history_mode """
- if context is None:
- context = {}
- if model and model == 'crm.lead' and res_id:
- lead = self.pool[model].browse(cr, uid, res_id, context=context)
- context['history_mode'] = history_mode
- body = self.get_record_data(cr, uid, 'crm.lead', res_id, context=context)['body']
- return {'value': {'body': body}}
-
- def create(self, cr, uid, values, context=None):
- """ TDE-HACK: remove 'type' from context, because when viewing an
- opportunity form view, a default_type is set and propagated
- to the wizard, that has a not matching type field. """
- default_type = context.pop('default_type', None)
- new_id = super(crm_lead_forward_to_partner, self).create(cr, uid, values, context=context)
- if default_type:
- context['default_type'] = default_type
- return new_id
-
def action_forward(self, cr, uid, ids, context=None):
- """ Forward the lead to a partner """
- if context is None:
+ lead_obj = self.pool.get('crm.lead')
+ record = self.browse(cr, uid, ids[0], context=context)
+ email_template_obj = self.pool.get('email.template')
+ try:
+ template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', 'email_template_lead_forward_mail')[1]
+ except ValueError:
+ raise osv.except_osv(_('Email Template Error'),
+ _('The Forward Email Template is not in the database'))
+ try:
+ portal_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_portal')[1]
+ except ValueError:
+ raise osv.except_osv(_('Portal Group Error'),
+ _('The Portal group cannot be found'))
+
+ local_context = context.copy()
+ if not (record.forward_type == 'single'):
+ no_email = set()
+ for lead in record.assignation_lines:
+ if lead.partner_assigned_id and not lead.partner_assigned_id.email:
+ no_email.add(lead.partner_assigned_id.name)
+ if no_email:
+ raise osv.except_osv(_('Email Error'),
+ ('Set an email address for the partner(s): %s' % ", ".join(no_email)))
+ if record.forward_type == 'single' and not record.partner_id.email:
+ raise osv.except_osv(_('Email Error'),
+ ('Set an email address for the partner %s' % record.partner_id.name))
+
+ partners_leads = {}
+ for lead in record.assignation_lines:
+ partner = record.forward_type == 'single' and record.partner_id or lead.partner_assigned_id
+ lead_details = {
+ 'lead_link': lead.lead_link,
+ 'lead_id': lead.lead_id,
+ }
+ if partner:
+ partner_leads = partners_leads.get(partner.id)
+ if partner_leads:
+ partner_leads['leads'].append(lead_details)
+ else:
+ partners_leads[partner.id] = {'partner': partner, 'leads': [lead_details]}
+ stage_id = False
+ if record.assignation_lines and record.assignation_lines[0].lead_id.type == 'lead':
+ try:
+ stage_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', 'stage_portal_lead_assigned')[1]
+ except ValueError:
+ pass
+
+ for partner_id, partner_leads in partners_leads.items():
+ in_portal = False
+ for contact in (partner.child_ids or [partner]):
+ if contact.user_ids:
+ in_portal = portal_id in [g.id for g in contact.user_ids[0].groups_id]
+
+ local_context['partner_id'] = partner_leads['partner']
+ local_context['partner_leads'] = partner_leads['leads']
+ local_context['partner_in_portal'] = in_portal
+ email_template_obj.send_mail(cr, uid, template_id, ids[0], context=local_context)
+ lead_ids = [lead['lead_id'].id for lead in partner_leads['leads']]
+ values = {'partner_assigned_id': partner_id, 'user_id': partner_leads['partner'].user_id.id}
+ if stage_id:
+ values['stage_id'] = stage_id
+ lead_obj.write(cr, uid, lead_ids, values)
+ self.pool.get('crm.lead').message_subscribe(cr, uid, lead_ids, [partner_id], context=context)
+ return True
+
+ def get_lead_portal_url(self, cr, uid, lead_id, type, context=None):
+ action = type == 'opportunity' and 'action_portal_opportunities' or 'action_portal_leads'
+ try:
+ action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', action)[1]
+ except ValueError:
+ action_id = False
+ portal_link = "%s/?db=%s#id=%s&action=%s&view_type=form" % (self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url'), cr.dbname, lead_id, action_id)
+ return portal_link
+
+ def get_portal_url(self, cr, uid, ids, context=None):
+ portal_link = "%s/?db=%s" % (self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url'), cr.dbname)
+ return portal_link
+
+ _columns = {
+ 'forward_type': fields.selection([('single', 'a single partner: manual selection of partner'), ('assigned', "several partners: automatic assignation, using GPS coordinates and partner's grades"), ], 'Forward selected leads to'),
+ 'partner_id': fields.many2one('res.partner', 'Forward Leads To'),
+ 'assignation_lines': fields.one2many('crm.lead.assignation', 'forward_id', 'Partner Assignation'),
+ 'body': fields.html('Contents', help='Automatically sanitized HTML contents'),
+ }
+
+ _defaults = {
+ 'forward_type': lambda self, cr, uid, c: c.get('forward_type') or 'single',
+ }
+
+
+class crm_lead_assignation (osv.TransientModel):
+ _name = 'crm.lead.assignation'
+ _columns = {
+ 'forward_id': fields.many2one('crm.lead.forward.to.partner', 'Partner Assignation'),
+ 'lead_id': fields.many2one('crm.lead', 'Lead'),
+ 'lead_location': fields.char('Lead Location', size=128),
+ 'partner_assigned_id': fields.many2one('res.partner', 'Assigned Partner'),
+ 'partner_location': fields.char('Partner Location', size=128),
+ 'lead_link': fields.char('Lead Single Links', size=128),
+ }
+
+ def on_change_lead_id(self, cr, uid, ids, lead_id, context=None):
+ if not context:
context = {}
- # TDE FIX in 7.0: force mass_mailing mode; this way, the message will be
- # send only to partners; default subtype of mass_mailing is indeed False
- # Chatter will show 'logged a note', but partner_ids (aka, the assigned partner)
- # will effectively receive the message if present in the composition window
- self.write(cr, uid, ids, {'composition_mode': 'mass_mail'}, context=context)
- res = {'type': 'ir.actions.act_window_close'}
- wizard = self.browse(cr, uid, ids[0], context=context)
- if wizard.model not in ('crm.lead'):
- return res
- if context.get('active_ids') is None:
- context['active_ids'] = [wizard.res_id]
+ if not lead_id:
+ return {'value': {'lead_location': False}}
+ lead = self.pool.get('crm.lead').browse(cr, uid, lead_id, context=context)
+ lead_location = []
+ if lead.country_id:
+ lead_location.append(lead.country_id.name)
+ if lead.city:
+ lead_location.append(lead.city)
+ return {'value': {'lead_location': ", ".join(lead_location)}}
- lead = self.pool[wizard.model]
- lead_ids = wizard.res_id and [wizard.res_id] or []
+ def on_change_partner_assigned_id(self, cr, uid, ids, partner_assigned_id, context=None):
+ if not context:
+ context = {}
+ if not partner_assigned_id:
+ return {'value': {'lead_location': False}}
+ partner = self.pool.get('res.partner').browse(cr, uid, partner_assigned_id, context=context)
+ partner_location = []
+ if partner.country_id:
+ partner_location.append(partner.country_id.name)
+ if partner.city:
+ partner_location.append(partner.city)
+ return {'value': {'partner_location': ", ".join(partner_location)}}
- if wizard.composition_mode == 'mass_mail':
- lead_ids = context and context.get('active_ids', []) or []
- value = self.default_get(cr, uid, ['body', 'email_to', 'email_cc', 'subject', 'history_mode'], context=context)
- value.pop('composition_mode')
- self.pool.get('crm.lead').message_subscribe(cr, uid, lead_ids, [partner.id for partner in wizard.partner_ids], context=context)
- self.write(cr, uid, ids, value, context=context)
-
- return self.send_mail(cr, uid, ids, context=context)
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+# # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml b/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml
index 0fda8c8beaa..26ad08f1528 100644
--- a/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml
+++ b/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml
@@ -1,36 +1,38 @@
-
crm_lead_forward_to_partner
crm.lead.forward.to.partner
@@ -45,14 +47,11 @@
new
-
+