[FIX]Convert to opportunities
bzr revid: hacker_on_test_server-20130201141811-s3byg8g19mya0fuk
This commit is contained in:
parent
822d1b3d13
commit
ef30f3a6a8
|
@ -219,6 +219,7 @@
|
|||
<field name="date_deadline" invisible="1"/>
|
||||
<field name="create_date" groups="base.group_no_one"/>
|
||||
<field name="name"/>
|
||||
<field name="type"/>
|
||||
<field name="contact_name"/>
|
||||
<field name="country_id" invisible="context.get('invisible_country', True)"/>
|
||||
<field name="email_from"/>
|
||||
|
|
|
@ -46,38 +46,35 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
lead_obj = self.pool.get('crm.lead')
|
||||
|
||||
res = super(crm_lead2opportunity_partner, self).default_get(cr, uid, fields, context=context)
|
||||
opportunities = res.get('opportunity_ids') or []
|
||||
partner_id = False
|
||||
email = False
|
||||
for lead in lead_obj.browse(cr, uid, opportunities, context=context):
|
||||
partner_id = lead.partner_id and lead.partner_id.id or False
|
||||
if context.get('active_id'):
|
||||
tomerge = set([int(context['active_id'])])
|
||||
|
||||
email = False
|
||||
partner_id = res.get('partner_id')
|
||||
lead = lead_obj.browse(cr, uid, int(context['active_id']), context=context)
|
||||
|
||||
#TOFIX: use mail.mail_message.to_mail
|
||||
email = re.findall(r'([^ ,<@]+@[^> ,]+)', lead.email_from or '')
|
||||
email = map(lambda x: "'" + x + "'", email)
|
||||
email = email[0]
|
||||
|
||||
if not partner_id and res.get('partner_id'):
|
||||
partner_id = res.get('partner_id')
|
||||
if partner_id:
|
||||
# Search for opportunities that have the same partner and that arent done or cancelled
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'opportunity')])
|
||||
for id in ids:
|
||||
tomerge.add(id)
|
||||
if email:
|
||||
ids = lead_obj.search(cr, uid, [('email_from', 'ilike', email), ('type', '=', 'opportunity')])
|
||||
for id in ids:
|
||||
tomerge.add(id)
|
||||
|
||||
ids = []
|
||||
if partner_id:
|
||||
# Search for opportunities that have the same partner and that arent done or cancelled
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'opportunity')])
|
||||
if ids:
|
||||
opportunities.append(ids[0])
|
||||
if email:
|
||||
ids = lead_obj.search(cr, uid, [('email', 'ilike', email), ('type', '=', 'opportunity')])
|
||||
if ids:
|
||||
opportunities.append(ids[0])
|
||||
|
||||
if 'action' in fields:
|
||||
res.update({'action' : partner_id and 'exist' or 'create'})
|
||||
if 'partner_id' in fields:
|
||||
res.update({'partner_id' : partner_id})
|
||||
if 'name' in fields:
|
||||
res.update({'name' : ids and 'merge' or 'convert'})
|
||||
if 'opportunity_ids' in fields:
|
||||
res.update({'opportunity_ids': opportunities})
|
||||
if 'action' in fields:
|
||||
res.update({'action' : partner_id and 'exist' or 'create'})
|
||||
if 'partner_id' in fields:
|
||||
res.update({'partner_id' : partner_id})
|
||||
if 'name' in fields:
|
||||
res.update({'name' : ids and 'merge' or 'convert'})
|
||||
if 'opportunity_ids' in fields and len(tomerge) >= 2:
|
||||
res.update({'opportunity_ids': list(tomerge)})
|
||||
|
||||
return res
|
||||
|
||||
|
|
|
@ -9,12 +9,20 @@
|
|||
<form string="Convert to Opportunity" version="7.0">
|
||||
<group name="name">
|
||||
<field name="name" class="oe_inline"/>
|
||||
<field name="opportunity_ids" attrs="{'invisible': [('name', '!=', 'merge')]}">
|
||||
</group>
|
||||
<group string="Opportunities">
|
||||
<field name="opportunity_ids" attrs="{'invisible': [('name', '!=', 'merge')]}" nolabel="1">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="user_id"/>
|
||||
<field name="section_id"/>
|
||||
<field name="create_date" groups="base.group_no_one"/>
|
||||
<field name="name"/>
|
||||
<field name="type"/>
|
||||
<field name="contact_name"/>
|
||||
<field name="country_id" invisible="context.get('invisible_country', True)"/>
|
||||
<field name="email_from"/>
|
||||
<field name="phone"/>
|
||||
<field name="stage_id"/>
|
||||
<field name="user_id" invisible="1"/>
|
||||
<field name="section_id" invisible="context.get('invisible_section', True)"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
|
|
Loading…
Reference in New Issue