diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 5ab68860874..2751405f454 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -610,9 +610,9 @@ class crm_lead(base_stage, format_address, osv.osv): } def convert_opportunity(self, cr, uid, ids, partner_id, user_ids=False, section_id=False, context=None): - partner = self.pool.get('res.partner') customer = False if partner_id: + partner = self.pool.get('res.partner') customer = partner.browse(cr, uid, partner_id, context=context) for lead in self.browse(cr, uid, ids, context=context): if lead.state in ('done', 'cancel'): diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index 2473a83206c..4a0467ccb2a 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -105,6 +105,7 @@ class crm_lead2opportunity_partner(osv.osv_memory): context = {} lead = self.pool.get('crm.lead') res = False + # FIXME: automatically creating a partner ? partner_ids_map = self._create_partner(cr, uid, ids, context=context) lead_ids = vals.get('lead_ids', []) team_id = vals.get('section_id', False) @@ -175,12 +176,19 @@ class crm_lead2opportunity_mass_convert(osv.osv_memory): return res def _convert_opportunity(self, cr, uid, ids, vals, context=None): + """ + When "massively" (more than one at a time) converting leads to + opportunities, check the salesteam_id and salesmen_ids and update + the values before calling super. + """ + if context is None: + context = {} data = self.browse(cr, uid, ids, context=context)[0] salesteam_id = data.section_id and data.section_id.id or False - salesman = [] + salesmen_ids = [] if data.user_ids: - salesman = [x.id for x in data.user_ids] - vals.update({'user_ids': salesman, 'section_id': salesteam_id}) + salesmen_ids = [x.id for x in data.user_ids] + vals.update({'user_ids': salesmen_ids, 'section_id': salesteam_id}) return super(crm_lead2opportunity_mass_convert, self)._convert_opportunity(cr, uid, ids, vals, context=context) def mass_convert(self, cr, uid, ids, context=None):