[MERGE] Sync with trunk
bzr revid: rim@openerp.com-20140305084807-vps6jxngvakr2sbr
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import project_issue
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- action of converting, via wizard -->
|
||||
<record model="ir.actions.act_window" id="convert_lead2projectissue_wizard_action" >
|
||||
<field name="name">Convert to Issue</field>
|
||||
<field name="res_model">crm.lead2projectissue.wizard</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- view of the Wizard Form -->
|
||||
<record model="ir.ui.view" id="view_crm_lead2projectissue_wizard" >
|
||||
<field name="name">crm.lead2projectissue.wizard.form</field>
|
||||
<field name="model">crm.lead2projectissue.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Convert to Issue" version="7.0">
|
||||
<group>
|
||||
<field name="project_id"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button type="object" name="action_lead_to_project_issue" string="Create Issue" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- inherit view of Lead Form : adding the "convert to issue" button -->
|
||||
<record model="ir.ui.view" id="crm_case_form_view_leads_project_issue">
|
||||
<field name="name">CRM - Leads Form</field>
|
||||
<field name="model">crm.lead</field>
|
||||
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='buttons']/button" position="after">
|
||||
<button name="%(convert_lead2projectissue_wizard_action)d" string="Convert to Issue" type="action" help="Convert to Issue" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1828,3 +1828,35 @@ class mail_thread(osv.AbstractModel):
|
||||
}
|
||||
threads.append(data)
|
||||
return sorted(threads, key=lambda x: (x['popularity'], x['id']), reverse=True)[:3]
|
||||
|
||||
def message_change_thread(self, cr, uid, id, new_res_id, new_model, context=None):
|
||||
"""
|
||||
Transfert the list of the mail thread messages from an model to another
|
||||
|
||||
:param id : the old res_id of the mail.message
|
||||
:param new_res_id : the new res_id of the mail.message
|
||||
:param new_model : the name of the new model of the mail.message
|
||||
|
||||
Example : self.pool.get("crm.lead").message_change_thread(self, cr, uid, 2, 4, "project.issue", context)
|
||||
will transfert thread of the lead (id=2) to the issue (id=4)
|
||||
"""
|
||||
|
||||
# get the sbtype id of the comment Message
|
||||
subtype_res_id = self.pool.get('ir.model.data').xmlid_to_res_id(cr, uid, 'mail.mt_comment', raise_if_not_found=True)
|
||||
|
||||
# get the ids of the comment and none-comment of the thread
|
||||
message_obj = self.pool.get('mail.message')
|
||||
msg_ids_comment = message_obj.search(cr, uid, [
|
||||
('model', '=', self._name),
|
||||
('res_id', '=', id),
|
||||
('subtype_id', '=', subtype_res_id)], context=context)
|
||||
msg_ids_not_comment = message_obj.search(cr, uid, [
|
||||
('model', '=', self._name),
|
||||
('res_id', '=', id),
|
||||
('subtype_id', '!=', subtype_res_id)], context=context)
|
||||
|
||||
# update the messages
|
||||
message_obj.write(cr, uid, msg_ids_comment, {"res_id" : new_res_id, "model" : new_model}, context=context)
|
||||
message_obj.write(cr, uid, msg_ids_not_comment, {"res_id" : new_res_id, "model" : new_model, "subtype_id" : None}, context=context)
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user