diff --git a/addons/crm_project_issue/__init__.py b/addons/crm_project_issue/__init__.py new file mode 100644 index 00000000000..9ef110bc4f7 --- /dev/null +++ b/addons/crm_project_issue/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import project_issue diff --git a/addons/crm_project_issue/__openerp__.py b/addons/crm_project_issue/__openerp__.py new file mode 100644 index 00000000000..3991cd306ec --- /dev/null +++ b/addons/crm_project_issue/__openerp__.py @@ -0,0 +1,20 @@ +{ + 'name': 'Lead to Issue', + 'version': '1.0', + 'summary': 'Create Issues from Leads', + 'sequence': '19', + 'category': 'Project Management', + 'complexity': 'easy', + 'author': 'OpenERP SA', + 'description': """ +Lead to Issues +============== + +Link module to map leads to issues + """, + 'data': [ + 'project_issue_view.xml' + ], + 'depends': ['crm', 'project_issue'], + 'installable': True, +} diff --git a/addons/crm_project_issue/project_issue.py b/addons/crm_project_issue/project_issue.py new file mode 100644 index 00000000000..fb600cb20d0 --- /dev/null +++ b/addons/crm_project_issue/project_issue.py @@ -0,0 +1,59 @@ + +from openerp.osv import osv, fields + + +class crm_lead_to_project_issue_wizard(osv.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)]) + } + + _defaults = { + "lead_id": lambda self, cr, uid, context=None: context.get('active_id') + } + + 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"] + + 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) + # move the mail thread + Lead.message_change_thread(cr, uid, lead.id, issue_id, "project.issue", context=context) + # delete the lead + Lead.unlink(cr, uid, [lead.id], context=None) + # return the action to go to the form view of the new Issue + view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'project.issue'), ('name', '=', 'project_issue_form_view')]) + return { + 'name': 'Issue created', + 'view_type': 'form', + 'view_mode': 'form', + 'view_id': view_id, + 'res_model': 'project.issue', + 'type': 'ir.actions.act_window', + 'res_id': issue_id, + 'context': context + } diff --git a/addons/crm_project_issue/project_issue_view.xml b/addons/crm_project_issue/project_issue_view.xml new file mode 100644 index 00000000000..b62e5f74880 --- /dev/null +++ b/addons/crm_project_issue/project_issue_view.xml @@ -0,0 +1,45 @@ + + + + + + + Convert to Issue + crm.lead2projectissue.wizard + form + form + new + + + + + crm.lead2projectissue.wizard.form + crm.lead2projectissue.wizard + +
+ + + +
+
+
+
+
+ + + + CRM - Leads Form + crm.lead + + + +