[IMP] remove a write() that sincerely seems useless

improve some var names

bzr revid: abo@openerp.com-20121119181224-c206f0xzuxw2hes0
This commit is contained in:
Antonin Bourguignon 2012-11-19 19:12:24 +01:00
parent 4d0b357664
commit 3dba2e5586
3 changed files with 45 additions and 21 deletions

View File

@ -545,7 +545,7 @@ class crm_lead(base_stage, format_address, osv.osv):
lead_ids = context.get('lead_ids', [])
if len(ids) <= 1:
raise osv.except_osv(_('Warning!'),_('Please select more than one opportunity from the list view.'))
raise osv.except_osv(_('Warning!'),_('Please select more than one element (lead or opportunity) from the list view.'))
ctx_opportunities = self.browse(cr, uid, lead_ids, context=context)
opportunities = self.browse(cr, uid, ids, context=context)
@ -740,25 +740,44 @@ class crm_lead(base_stage, format_address, osv.osv):
self.schedule_phonecall_send_note(cr, uid, [lead.id], new_id, action, context=context)
return phonecall_dict
def redirect_opportunity_view(self, cr, uid, opportunity_id, context=None):
models_data = self.pool.get('ir.model.data')
# Get Opportunity views
# Get opportunity views
form_view = models_data.get_object_reference(cr, uid, 'crm', 'crm_case_form_view_oppor')
tree_view = models_data.get_object_reference(cr, uid, 'crm', 'crm_case_tree_view_oppor')
return {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'crm.lead',
'domain': [('type', '=', 'opportunity')],
'res_id': int(opportunity_id),
'view_id': False,
'views': [(form_view and form_view[1] or False, 'form'),
(tree_view and tree_view[1] or False, 'tree'),
(False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'crm.lead',
'domain': [('type', '=', 'opportunity')],
'res_id': int(opportunity_id),
'view_id': False,
'views': [(form_view and form_view[1] or False, 'form'),
(tree_view and tree_view[1] or False, 'tree'),
(False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
}
def redirect_lead_view(self, cr, uid, lead_id, context=None):
models_data = self.pool.get('ir.model.data')
# Get lead views
form_view = models_data.get_object_reference(cr, uid, 'crm', 'crm_case_form_view_leads')
tree_view = models_data.get_object_reference(cr, uid, 'crm', 'crm_case_tree_view_leads')
return {
'name': _('Lead'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'crm.lead',
'domain': [('type', '=', 'lead')],
'res_id': int(lead_id),
'view_id': False,
'views': [(form_view and form_view[1] or False, 'form'),
(tree_view and tree_view[1] or False, 'tree'),
(False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
}
def action_makeMeeting(self, cr, uid, ids, context=None):

View File

@ -245,7 +245,6 @@
</field>
</record>
<!-- CRM Lead Tree View -->
<record model="ir.ui.view" id="crm_case_tree_view_leads">
<field name="name">Leads</field>

View File

@ -37,16 +37,22 @@ class crm_merge_opportunity(osv.osv_memory):
}
def action_merge(self, cr, uid, ids, context=None):
"""
Different cases of merge:
- merge 2 leads together = 1 new lead
- merge 2 opps together = 1 new opp
- merge 1 lead and 1 opp together = 1 new opp
"""
if context is None:
context = {}
lead = self.pool.get('crm.lead')
wizard = self.browse(cr, uid, ids[0], context=context)
opportunities = wizard.opportunity_ids
#TOFIX: why need to check lead_ids here
lead_ids = [opportunities[0].id]
self.write(cr, uid, ids, {'opportunity_ids' : [(6,0, lead_ids)]}, context=context)
context['lead_ids'] = lead_ids
merge_id = lead.merge_opportunity(cr, uid, [x.id for x in opportunities], context=context)
opportunity2merge_ids = wizard.opportunity_ids
#TODO: why is this passed through the context, and not as an argument ? It looks dirty...
context['lead_ids'] = [opportunity2merge_ids[0].id]
merge_id = lead.merge_opportunity(cr, uid, [x.id for x in opportunity2merge_ids], context=context)
return lead.redirect_opportunity_view(cr, uid, merge_id, context=context)
def default_get(self, cr, uid, fields, context=None):