diff --git a/addons/crm_project_issue/__openerp__.py b/addons/crm_project_issue/__openerp__.py index 6479c9a9405..7f6e9d8cb66 100644 --- a/addons/crm_project_issue/__openerp__.py +++ b/addons/crm_project_issue/__openerp__.py @@ -1,6 +1,7 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. { 'name': 'Lead to Issue', - 'version': '1.0', 'summary': 'Create Issues from Leads', 'sequence': '19', 'category': 'Project Management', @@ -16,5 +17,4 @@ Link module to map leads to issues 'views/crm_lead_views.xml' ], 'depends': ['crm', 'project_issue'], - 'installable': True, } diff --git a/addons/crm_project_issue/views/crm_lead_views.xml b/addons/crm_project_issue/views/crm_lead_views.xml index 534ab2f8b0d..748529ed576 100644 --- a/addons/crm_project_issue/views/crm_lead_views.xml +++ b/addons/crm_project_issue/views/crm_lead_views.xml @@ -8,7 +8,7 @@ - + Convert To Issue diff --git a/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard.py b/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard.py index 6d6dcad8333..a382bf07128 100644 --- a/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard.py +++ b/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard.py @@ -1,67 +1,58 @@ -from openerp.osv import osv, fields +from odoo import api, fields, models -class crm_lead_to_project_issue_wizard(osv.TransientModel): +class CrmLeadToProjectIssueWizard(models.TransientModel): """ wizard to convert a Lead into a Project Issue and move the Mail Thread """ + _name = "crm.lead2projectissue.wizard" _inherit = 'crm.partner.binding' - _columns = { - "lead_id": fields.many2one("crm.lead", "Lead", domain=[("type", "=", "lead")]), - "project_id": fields.many2one("project.project", "Project", domain=[("use_issues", "=", True)]) - } + @api.model + def default_get(self, fields): + result = super(CrmLeadToProjectIssueWizard, self).default_get(fields) + lead_id = self.env.context.get('active_id') + if lead_id: + result['lead_id'] = lead_id + return result - _defaults = { - "lead_id": lambda self, cr, uid, context=None: context.get('active_id') - } + lead_id = fields.Many2one('crm.lead', string='Lead', domain=[('type', '=', 'lead')]) + project_id = fields.Many2one('project.project', string='Project', domain=[('use_issues', '=', True)]) - def action_lead_to_project_issue(self, cr, uid, ids, context=None): - # get the wizards and models - wizards = self.browse(cr, uid, ids, context=context) - Lead = self.pool["crm.lead"] - Issue = self.pool["project.issue"] - Attachment = self.pool['ir.attachment'] - - for wizard in wizards: - # get the lead to transform - lead = wizard.lead_id - - partner = self._find_matching_partner(cr, uid, context=context) - if not partner and (lead.partner_name or lead.contact_name): - partner_ids = Lead.handle_partner_assignation(cr, uid, [lead.id], context=context) - partner = partner_ids[lead.id] - - # create new project.issue - vals = { - "name": lead.name, - "description": lead.description, - "email_from": lead.email_from, - "project_id": wizard.project_id.id, - "partner_id": partner, - "user_id": None - } - issue_id = Issue.create(cr, uid, vals, context=None) - issue = Issue.browse(cr, uid, issue_id, context=None) - # move the mail thread - Lead.message_change_thread(cr, uid, [lead.id], issue, context=context) - # Move attachments - attachment_ids = Attachment.search( - cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', lead.id)], context=context) - Attachment.write( - cr, uid, attachment_ids, {'res_model': 'project.issue', 'res_id': issue_id}, context=context) - # Archive the lead - Lead.write(cr, uid, [lead.id], {'active': False}, context=context) + @api.multi + def action_lead_to_project_issue(self): + self.ensure_one() + # get the lead to transform + lead = self.lead_id + partner_id = self._find_matching_partner() + if not partner_id and (lead.partner_name or lead.contact_name): + partner_id = lead.handle_partner_assignation()[lead.id] + # create new project.issue + vals = { + "name": lead.name, + "description": lead.description, + "email_from": lead.email_from, + "project_id": self.project_id.id, + "partner_id": partner_id, + "user_id": None + } + issue = self.env['project.issue'].create(vals) + # move the mail thread + lead.message_change_thread(issue) + # move attachments + attachments = self.env['ir.attachment'].search([('res_model', '=', 'crm.lead'), ('res_id', '=', lead.id)]) + attachments.write({'res_model': 'project.issue', 'res_id': issue.id}) + # archive the lead + lead.write({'active': False}) # return the action to go to the form view of the new Issue - view_id = self.pool['ir.model.data'].xmlid_to_res_id( - cr, uid, 'project_issue.project_issue_form_view') + view = self.env.ref('project_issue.project_issue_form_view') return { 'name': 'Issue created', 'view_type': 'form', 'view_mode': 'form', - 'view_id': view_id, + 'view_id': view.id, 'res_model': 'project.issue', 'type': 'ir.actions.act_window', - 'res_id': issue_id, - 'context': context + 'res_id': issue.id, + 'context': self.env.context } diff --git a/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard_view.xml b/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard_view.xml index d09af76529f..0405e9ac5cf 100644 --- a/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard_view.xml +++ b/addons/crm_project_issue/wizard/crm_lead2projectissue_wizard_view.xml @@ -1,18 +1,8 @@ - - - - - - Convert to Issue - crm.lead2projectissue.wizard - form - form - new - + - + crm.lead2projectissue.wizard.form crm.lead2projectissue.wizard @@ -28,5 +18,13 @@ - - + + + Convert to Issue + crm.lead2projectissue.wizard + form + form + new + + +