2 from openerp.osv import osv, fields
5 class crm_lead_to_project_issue_wizard(osv.TransientModel):
6 """ wizard to convert a Lead into a Project Issue and move the Mail Thread """
7 _name = "crm.lead2projectissue.wizard"
8 _inherit = 'crm.partner.binding'
11 "lead_id": fields.many2one("crm.lead", "Lead", domain=[("type", "=", "lead")]),
12 "project_id": fields.many2one("project.project", "Project", domain=[("use_issues", "=", True)])
16 "lead_id": lambda self, cr, uid, context=None: context.get('active_id')
19 def action_lead_to_project_issue(self, cr, uid, ids, context=None):
20 # get the wizards and models
21 wizards = self.browse(cr, uid, ids, context=context)
22 Lead = self.pool["crm.lead"]
23 Issue = self.pool["project.issue"]
25 for wizard in wizards:
26 # get the lead to transform
29 partner = self._find_matching_partner(cr, uid, context=context)
30 if not partner and (lead.partner_name or lead.contact_name):
31 partner_ids = Lead.handle_partner_assignation(cr, uid, [lead.id], context=context)
32 partner = partner_ids[lead.id]
34 # create new project.issue
37 "description": lead.description,
38 "email_from": lead.email_from,
39 "project_id": wizard.project_id.id,
40 "partner_id": partner,
43 issue_id = Issue.create(cr, uid, vals, context=None)
44 # move the mail thread
45 Lead.message_change_thread(cr, uid, lead.id, issue_id, "project.issue", context=context)
47 Lead.unlink(cr, uid, [lead.id], context=None)
48 # return the action to go to the form view of the new Issue
49 view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'project.issue'), ('name', '=', 'project_issue_form_view')])
51 'name': 'Issue created',
55 'res_model': 'project.issue',
56 'type': 'ir.actions.act_window',