[IMP] crm: better management of contact / company / customer when going
from a lead to an opportunity.
This commit is contained in:
committed by
Thibault Delavallée
parent
2ec6fe68a1
commit
32fb2f0940
+13
-14
@@ -752,19 +752,19 @@ class crm_lead(format_address, osv.osv):
|
||||
return partner
|
||||
|
||||
def _create_lead_partner(self, cr, uid, lead, context=None):
|
||||
partner_id = False
|
||||
if lead.partner_name and lead.contact_name:
|
||||
partner_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, True, context=context)
|
||||
partner_id = self._lead_create_contact(cr, uid, lead, lead.contact_name, False, partner_id, context=context)
|
||||
elif lead.partner_name and not lead.contact_name:
|
||||
partner_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, True, context=context)
|
||||
elif not lead.partner_name and lead.contact_name:
|
||||
partner_id = self._lead_create_contact(cr, uid, lead, lead.contact_name, False, context=context)
|
||||
elif lead.email_from and self.pool.get('res.partner')._parse_partner_name(lead.email_from, context=context)[0]:
|
||||
contact_name = self.pool.get('res.partner')._parse_partner_name(lead.email_from, context=context)[0]
|
||||
partner_id = self._lead_create_contact(cr, uid, lead, contact_name, False, context=context)
|
||||
contact_id = False
|
||||
contact_name = lead.contact_name or lead.email_from and self.pool.get('res.partner')._parse_partner_name(lead.email_from, context=context)[0] or False
|
||||
if lead.partner_name:
|
||||
partner_company_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, True, context=context)
|
||||
elif lead.partner_id:
|
||||
partner_company_id = lead.partner_id.id
|
||||
else:
|
||||
raise UserError(_('No customer name defined. Please fill one of the following fields: Company Name, Contact Name or Email ("Name <email@address>")'))
|
||||
partner_company_id = False
|
||||
|
||||
if contact_name:
|
||||
contact_id = self._lead_create_contact(cr, uid, lead, contact_name, False, partner_company_id, context=context)
|
||||
|
||||
partner_id = contact_id or partner_company_id or self._lead_create_contact(cr, uid, lead, lead.name, False, context=context)
|
||||
return partner_id
|
||||
|
||||
def handle_partner_assignation(self, cr, uid, ids, action='create', partner_id=False, context=None):
|
||||
@@ -784,8 +784,7 @@ class crm_lead(format_address, osv.osv):
|
||||
# If the action is set to 'create' and no partner_id is set, create a new one
|
||||
if lead.partner_id:
|
||||
partner_ids[lead.id] = lead.partner_id.id
|
||||
continue
|
||||
if not partner_id and action == 'create':
|
||||
if action == 'create':
|
||||
partner_id = self._create_lead_partner(cr, uid, lead, context)
|
||||
self.pool['res.partner'].write(cr, uid, partner_id, {'team_id': lead.team_id and lead.team_id.id or False})
|
||||
if partner_id:
|
||||
|
||||
@@ -79,6 +79,8 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
||||
res.update({'user_id': lead.user_id.id})
|
||||
if lead.team_id:
|
||||
res.update({'team_id': lead.team_id.id})
|
||||
if not partner_id and not lead.contact_name:
|
||||
res.update({'action': 'nothing'})
|
||||
return res
|
||||
|
||||
def on_change_user(self, cr, uid, ids, user_id, team_id, context=None):
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Convert to Opportunity">
|
||||
<group name="name">
|
||||
<field name="name" class="oe_inline"/>
|
||||
<field name="name" class="oe_inline" widget="radio"/>
|
||||
</group>
|
||||
<group string="Assign opportunities to">
|
||||
<group string="Assign these opportunities to">
|
||||
<field name="user_id" class="oe_inline" on_change="on_change_user(user_id, team_id, context)"/>
|
||||
<field name="team_id" class="oe_inline" groups="base.group_multi_salesteams"/>
|
||||
</group>
|
||||
<group string="Opportunities">
|
||||
<field name="opportunity_ids" attrs="{'invisible': [('name', '!=', 'merge')]}" nolabel="1">
|
||||
<group string="Opportunities" attrs="{'invisible': [('name', '!=', 'merge')]}">
|
||||
<field name="opportunity_ids" nolabel="1">
|
||||
<tree>
|
||||
<field name="create_date"/>
|
||||
<field name="name"/>
|
||||
@@ -30,11 +30,12 @@
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<group name="action" attrs="{'invisible': [('name', '!=', 'convert')]}">
|
||||
<field name="action" on_change="onchange_action(action, context)" class="oe_inline"/>
|
||||
<field name="partner_id"
|
||||
attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}"
|
||||
class="oe_inline"/>
|
||||
<group name="action" attrs="{'invisible': [('name', '!=', 'convert')]}" string="Customers" col="1">
|
||||
<field name="action" class="oe_inline" nolabel="1" widget="radio" on_change="onchange_action(action, context)" />
|
||||
<group col="2">
|
||||
<field name="partner_id" attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}"
|
||||
class="oe_inline"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_apply" string="Create Opportunity" type="object" class="oe_highlight"/>
|
||||
@@ -52,7 +53,7 @@
|
||||
<form string="Convert to Opportunity">
|
||||
<separator string="Conversion Options"/>
|
||||
<group>
|
||||
<field name="action" class="oe_inline" on_change="on_change_action(action)"/>
|
||||
<field name="name" class="oe_inline" widget="radio"/>
|
||||
<field name="deduplicate" class="oe_inline" on_change="on_change_deduplicate(deduplicate, context)"/>
|
||||
</group>
|
||||
<group string="Assign opportunities to">
|
||||
@@ -78,6 +79,14 @@
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<group attrs="{'invisible': [('name', '!=', 'convert')]}" string="Customers" col="1">
|
||||
<field name="action" class="oe_inline" widget="radio"/>
|
||||
<group col="2">
|
||||
<field name="partner_id"
|
||||
attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}"
|
||||
class="oe_inline"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="mass_convert" string="Convert to Opportunities" type="object" class="oe_highlight"/>
|
||||
or
|
||||
|
||||
Reference in New Issue
Block a user