From 1df211b6936423d9d8c18dc078941a6ef0becd35 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 5 Dec 2012 20:21:46 +0100 Subject: [PATCH] [IMP] rename methods in crm_lead and crm_phonecall: in these classes, the method convert_partner() is now named handle_partner_assignation() also the method in crm_phonecall has received the same refactoring than the one in crm_lead documentation has been improved these two method are a pure code duplication and would deserve a refactoring bzr revid: abo@openerp.com-20121205192146-rogbsln3atcm1lvt --- addons/crm/crm_lead.py | 5 +++-- addons/crm/crm_phonecall.py | 18 +++++++++++------- .../process/communication_with_customer.yml | 2 +- addons/crm/wizard/crm_partner_binding.py | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index c4414d76edf..4adab335d81 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -754,17 +754,18 @@ class crm_lead(base_stage, format_address, osv.osv): self._lead_set_partner_send_note(cr, uid, [lead.id], context) return res - def convert_partner(self, cr, uid, ids, action='create', partner_id=False, context=None): + def handle_partner_assignation(self, cr, uid, ids, action='create', partner_id=False, context=None): """ Handle partner assignation during a lead conversion. if action is 'create', create new partner with contact and assign lead to new partner_id. - otherwise assign lead to specified partner_id + otherwise assign lead to the specified partner_id :param list ids: leads/opportunities ids to process :param string action: what has to be done regarding partners (create it, assign an existing one, or nothing) :param int partner_id: partner to assign if any :return dict: dictionary organized as followed: {lead_id: partner_assigned_id} """ + #TODO this is a pure diplucation of the handle_partner_assignation method of crm_phonecall partner_ids = {} for lead in self.browse(cr, uid, ids, context=context): # If the action is set to 'create' and no partner_id is set, create a new one diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py index 2acca586f97..f02421d1ee8 100644 --- a/addons/crm/crm_phonecall.py +++ b/addons/crm/crm_phonecall.py @@ -170,19 +170,23 @@ class crm_phonecall(base_state, osv.osv): 'phone': phonecall.partner_phone, }) - def convert_partner(self, cr, uid, ids, action='create', partner_id=False, context=None): + def handle_partner_assignation(self, cr, uid, ids, action='create', partner_id=False, context=None): """ - This function convert partner based on action. + Handle partner assignation during a lead conversion. if action is 'create', create new partner with contact and assign lead to new partner_id. otherwise assign lead to specified partner_id + + :param list ids: phonecalls ids to process + :param string action: what has to be done regarding partners (create it, assign an existing one, or nothing) + :param int partner_id: partner to assign if any + :return dict: dictionary organized as followed: {lead_id: partner_assigned_id} """ - if context is None: - context = {} + #TODO this is a pure diplucation of the handle_partner_assignation method of crm_lead partner_ids = {} - force_partner_id = partner_id for call in self.browse(cr, uid, ids, context=context): - if action == 'create': - partner_id = force_partner_id or self._call_create_partner(cr, uid, call, context=context) + # If the action is set to 'create' and no partner_id is set, create a new one + if action == 'create' and not partner_id: + partner_id = self._call_create_partner(cr, uid, call, context) self._call_create_partner_address(cr, uid, call, partner_id, context=context) self._call_set_partner(cr, uid, [call.id], partner_id, context=context) partner_ids[call.id] = partner_id diff --git a/addons/crm/test/process/communication_with_customer.yml b/addons/crm/test/process/communication_with_customer.yml index 387d4589714..148d08dfc49 100644 --- a/addons/crm/test/process/communication_with_customer.yml +++ b/addons/crm/test/process/communication_with_customer.yml @@ -33,4 +33,4 @@ - !python {model: crm.lead}: | lead_ids = self.search(cr, uid, [('email_from','=', 'Mr. John Right ')]) - self.convert_partner(cr, uid, lead_ids, context=context) + self.handle_partner_assignation(cr, uid, lead_ids, context=context) diff --git a/addons/crm/wizard/crm_partner_binding.py b/addons/crm/wizard/crm_partner_binding.py index bea7134fbec..8b177c080a8 100644 --- a/addons/crm/wizard/crm_partner_binding.py +++ b/addons/crm/wizard/crm_partner_binding.py @@ -102,6 +102,6 @@ class crm_partner_binding(osv.osv_memory): lead_ids = context.get('active_ids', []) data = self.browse(cr, uid, ids, context=context)[0] partner_id = data.partner_id and data.partner_id.id or False - return lead.convert_partner(cr, uid, lead_ids, data.action, partner_id, context=context) + return lead.handle_partner_assignation(cr, uid, lead_ids, data.action, partner_id, context=context) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: