From 21dd35ede560a2f15a61525a9526566c1dc62e73 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 20 Jun 2013 17:19:07 +0200 Subject: [PATCH] [ADD&FIX]crm_channel: add wizard for buttons interested & not, fix portal url bzr revid: dle@openerp.com-20130620151907-qeu1c2wkk5vs72l7 --- addons/crm_channel/__openerp__.py | 1 + addons/crm_channel/crm_data.xml | 6 +++ addons/crm_channel/crm_lead.py | 37 ++++++------------- addons/crm_channel/static/src/js/next.js | 1 + addons/crm_channel/wizard/__init__.py | 1 + .../wizard/crm_forward_to_partner.py | 35 ++++++++---------- .../wizard/crm_forward_to_partner_view.xml | 1 - 7 files changed, 36 insertions(+), 46 deletions(-) diff --git a/addons/crm_channel/__openerp__.py b/addons/crm_channel/__openerp__.py index c0c1e6ef30f..2d14e7caa22 100644 --- a/addons/crm_channel/__openerp__.py +++ b/addons/crm_channel/__openerp__.py @@ -43,6 +43,7 @@ You can also use the geolocalization without using the GPS coordinates. '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_channel_data.xml', 'crm_data.xml', diff --git a/addons/crm_channel/crm_data.xml b/addons/crm_channel/crm_data.xml index 89c84bff9d2..31ad686e2d9 100644 --- a/addons/crm_channel/crm_data.xml +++ b/addons/crm_channel/crm_data.xml @@ -3,6 +3,12 @@ + + Assigned + + + + To Recycle diff --git a/addons/crm_channel/crm_lead.py b/addons/crm_channel/crm_lead.py index d08425729a1..2639e92d60a 100644 --- a/addons/crm_channel/crm_lead.py +++ b/addons/crm_channel/crm_lead.py @@ -20,38 +20,25 @@ ############################################################################## from openerp.osv import osv -from openerp import SUPERUSER_ID from openerp.tools.translate import _ class crm_lead(osv.osv): _inherit = 'crm.lead' - def case_interested(self, cr, uid, ids, context=None): - self.check_access_rights(cr, uid, 'write') + def get_interested_action(self, cr, uid, interested, context=None): try: - stage_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_channel', 'stage_portal_lead_interested')[1] + model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_channel', 'crm_lead_channel_interested_act') except ValueError: - stage_id = False - if stage_id: - self.write(cr, SUPERUSER_ID, ids, {'stage_id': stage_id}) - self.message_post(cr, uid, ids, body=_('I am interested by this lead'), context=context) + 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): - self.check_access_rights(cr, uid, 'write') - try: - stage_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_channel', 'stage_portal_lead_recycle')[1] - except ValueError: - stage_id = False - values = {} - values = {'partner_assigned_id': False} - if stage_id: - values['stage_id'] = stage_id - self.message_post(cr, uid, ids, body=_('I am not interested by this lead'), context=context) - self.write(cr, SUPERUSER_ID, ids, values, context=context) - return { - 'type': 'ir.actions.client', - 'tag': 'next_or_list', - 'params': { - }, - } + return self.get_interested_action(cr, uid, False, context=context) diff --git a/addons/crm_channel/static/src/js/next.js b/addons/crm_channel/static/src/js/next.js index 4f0c58c0e18..53614c0ee64 100644 --- a/addons/crm_channel/static/src/js/next.js +++ b/addons/crm_channel/static/src/js/next.js @@ -7,6 +7,7 @@ openerp.crm_channel = function (instance) { 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_channel.next_or_list"); } \ No newline at end of file diff --git a/addons/crm_channel/wizard/__init__.py b/addons/crm_channel/wizard/__init__.py index 9224173145b..ab6c7b7f06a 100644 --- a/addons/crm_channel/wizard/__init__.py +++ b/addons/crm_channel/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_channel/wizard/crm_forward_to_partner.py b/addons/crm_channel/wizard/crm_forward_to_partner.py index d54a96d527a..58501e511ab 100644 --- a/addons/crm_channel/wizard/crm_forward_to_partner.py +++ b/addons/crm_channel/wizard/crm_forward_to_partner.py @@ -28,8 +28,7 @@ class crm_lead_forward_to_partner(osv.TransientModel): """ Forward info history to partners. """ _name = 'crm.lead.forward.to.partner' - def _convert_to_assignation_line(self, cr, uid, lead, partner): - base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') + def _convert_to_assignation_line(self, cr, uid, lead, partner, context=None): lead_location = [] partner_location = [] if lead.country_id: @@ -45,7 +44,7 @@ class crm_lead_forward_to_partner(osv.TransientModel): 'lead_location': ", ".join(lead_location), 'partner_assigned_id': partner and partner.id or False, 'partner_location': ", ".join(partner_location), - 'lead_link': "%s/?db=%s#id=%s&model=crm.lead" % (base_url, cr.dbname, lead.id) + 'lead_link': self.get_portal_url(cr, uid, lead.id, context=context), } def default_get(self, cr, uid, fields, context=None): @@ -89,10 +88,10 @@ class crm_lead_forward_to_partner(osv.TransientModel): _('The Forward Email Template is not in the database')) local_context = context.copy() if not (record.forward_type == 'single'): - no_email = [] + no_email = set() for lead in record.assignation_lines: if lead.partner_assigned_id and not lead.partner_assigned_id.email: - no_email.append(lead.partner_assigned_id.name) + 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))) @@ -113,29 +112,25 @@ class crm_lead_forward_to_partner(osv.TransientModel): partner_leads['leads'].append(lead_details) else: partners_leads[partner.id] = {'partner': partner, 'leads': [lead_details]} + try: + stage_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_channel', 'stage_portal_lead_assigned')[1] + except ValueError: + stage_id = False for partner_id, partner_leads in partners_leads.items(): local_context['partner_id'] = partner_leads['partner'] local_context['partner_leads'] = partner_leads['leads'] 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']] - lead_obj.write(cr, uid, lead_ids, {'partner_assigned_id': partner_id, 'user_id': partner_leads['partner'].user_id.id}) + lead_obj.write(cr, uid, lead_ids, {'partner_assigned_id': partner_id, 'user_id': partner_leads['partner'].user_id.id, 'stage_id': stage_id}) self.pool.get('crm.lead').message_subscribe(cr, uid, lead_ids, [partner_id], context=context) return True - # def action_clean_lines(self, cr, uid, ids, context=None): - # record = self.browse(cr, uid, ids[0], context=context) - # invalid_lines = [] - # for line in record.assignation_lines: - # if not line.partner_assigned_id: - # invalid_lines.append((2, line.id)) - # self.write(cr, uid, ids[0], {'assignation_lines': invalid_lines}, context=context) - # model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_channel', 'action_crm_send_mass_forward') - # action = self.pool[model].read(cr, uid, action_id, context=context) - # action['res_id'] = ids[0] - # return action - - 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) + def get_portal_url(self, cr, uid, lead_id, context=None): + try: + action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_channel', 'action_portal_leads')[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 _columns = { diff --git a/addons/crm_channel/wizard/crm_forward_to_partner_view.xml b/addons/crm_channel/wizard/crm_forward_to_partner_view.xml index 11598558f00..26ad08f1528 100644 --- a/addons/crm_channel/wizard/crm_forward_to_partner_view.xml +++ b/addons/crm_channel/wizard/crm_forward_to_partner_view.xml @@ -16,7 +16,6 @@ -