[FIX] crm: correct open lead or opportunity view from calls
authorRavi Gohil <rgo@tinyerp.com>
Mon, 9 Jun 2014 09:28:30 +0000 (14:58 +0530)
committerMartin Trigaux <mat@openerp.com>
Wed, 24 Sep 2014 13:54:44 +0000 (15:54 +0200)
When opening a lead/opportunity from the phonecalls view, we did not open the correct view (always the lead).
This will use the type of the crm.lead to determine which view should be used, opw 608493.

addons/crm/crm_lead.py
addons/crm/crm_phonecall_view.xml

index 6c4ef60..b04eae9 100644 (file)
@@ -165,6 +165,11 @@ 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):
+        if view_type == 'form' and context and context.get('opportunity_id'):
+            # TODO: replace by get_formview_action call
+            lead_type = self.browse(cr, user, context['opportunity_id'], context=context).type
+            view_lead_xml_id = 'crm_case_form_view_oppor' if lead_type == 'opportunity' else 'crm_case_form_view_leads'
+            _, view_id = self.pool['ir.model.data'].get_object_reference(cr, user, 'crm', view_lead_xml_id)
         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)
index 21e18d8..4737065 100644 (file)
                             domain="[('object_id.model', '=', 'crm.phonecall')]"/>
                         <field name="partner_mobile"/>
                         <field name="priority"/>
-                        <field name="opportunity_id" on_change="on_change_opportunity(opportunity_id)"/>
+                        <field name="opportunity_id" on_change="on_change_opportunity(opportunity_id)" context="{'opportunity_id': opportunity_id}"/>
                     </group>
                     <field name="description" placeholder="Description..."/>
                 </sheet>