diff --git a/helpdesk_mgmt_crm/README.rst b/helpdesk_mgmt_crm/README.rst new file mode 100644 index 0000000000..a1b9bade52 --- /dev/null +++ b/helpdesk_mgmt_crm/README.rst @@ -0,0 +1,100 @@ +============================= +Link between Helpdesk and CRM +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e4949b62cea363d636d67d6d8d8327c15674c38e905148455981c9ecaed8aca6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhelpdesk-lightgray.png?logo=github + :target: https://github.com/OCA/helpdesk/tree/15.0/helpdesk_mgmt_crm + :alt: OCA/helpdesk +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/helpdesk-15-0/helpdesk-15-0-helpdesk_mgmt_crm + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/helpdesk&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to convert a helpdesk ticket into an opportunity, transferring its messages, +and keeping both linked. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Go to *Helpdesk > Tickets* and create a new one or enter one. +#. Click on "Convert to opportunity" button. +#. A wizard will be displayed to set user and sales team if you want. +#. Click on "Create opportunity" button. +#. An opportunity will have been created with the ticket data and the messages will have been copied. +#. The related ticket will be displayed so you can return to it. +#. An "Opportunity(ies)" smart-button is also displayed on the ticket. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + * Pilar Vargas + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/helpdesk `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/helpdesk_mgmt_crm/__init__.py b/helpdesk_mgmt_crm/__init__.py new file mode 100644 index 0000000000..9b4296142f --- /dev/null +++ b/helpdesk_mgmt_crm/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/helpdesk_mgmt_crm/__manifest__.py b/helpdesk_mgmt_crm/__manifest__.py new file mode 100644 index 0000000000..65585c5ddb --- /dev/null +++ b/helpdesk_mgmt_crm/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Link between Helpdesk and CRM", + "summary": "Links helpdesk tickets with leads", + "version": "15.0.1.0.1", + "category": "After-Sales", + "website": "https://github.com/OCA/helpdesk", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["helpdesk_mgmt", "crm"], + "data": [ + "security/ir.model.access.csv", + "wizard/helpdesk_ticket_create_lead_views.xml", + "views/crm_lead_view.xml", + "views/helpdesk_ticket_view.xml", + ], + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/helpdesk_mgmt_crm/i18n/es.po b/helpdesk_mgmt_crm/i18n/es.po new file mode 100644 index 0000000000..8c22ea4e0d --- /dev/null +++ b/helpdesk_mgmt_crm/i18n/es.po @@ -0,0 +1,126 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * helpdesk_mgmt_crm +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-09-09 06:40+0000\n" +"PO-Revision-Date: 2022-09-09 08:41+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: helpdesk_mgmt_crm +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_view_form +msgid "Cancel" +msgstr "Cancelar" + +#. module: helpdesk_mgmt_crm +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.ticket_view_form +msgid "Convert to opportunity" +msgstr "Convertir a oportunidad" + +#. module: helpdesk_mgmt_crm +#: model:ir.actions.act_window,name:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_action +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_view_form +msgid "Create Lead" +msgstr "Crear Oportunidad" + +#. module: helpdesk_mgmt_crm +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_view_form +msgid "Create opportunity" +msgstr "Crear oportunidad" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__display_name +msgid "Display Name" +msgstr "Fecha a mostrar" + +#. module: helpdesk_mgmt_crm +#: model:ir.model,name:helpdesk_mgmt_crm.model_helpdesk_ticket +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_crm_lead__ticket_id +msgid "Helpdesk Ticket" +msgstr "Solicitud de asistencia" + +#. module: helpdesk_mgmt_crm +#: model:ir.model,name:helpdesk_mgmt_crm.model_helpdesk_ticket_create_lead +msgid "Helpdesk Ticket Create Lead" +msgstr "Crear oportunidad desde solicitud de asistencia" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__id +msgid "ID" +msgstr "ID" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__write_uid +msgid "Last Updated by" +msgstr "Última actualización de" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__write_date +msgid "Last Updated on" +msgstr "Actualizado el" + +#. module: helpdesk_mgmt_crm +#: model:ir.model,name:helpdesk_mgmt_crm.model_crm_lead +msgid "Lead/Opportunity" +msgstr "Iniciativa/Oportunidad" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket__lead_count +msgid "Opportunity Count" +msgstr "Total oportunidades" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket__lead_ids +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.ticket_view_form +msgid "Opportunity(ies)" +msgstr "Oportunidad(es)" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__team_id +msgid "Team" +msgstr "Equipo" + +#. module: helpdesk_mgmt_crm +#: code:addons/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead.py:0 +#, python-format +msgid "" +"This ticket has been converted to the opportunity %(name)s" +msgstr "" +"Esta solicitud se ha convertido en la oportunidad %(name)s" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__ticket_id +msgid "Ticket" +msgstr "Solicitud" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__user_id +msgid "User" +msgstr "Usuario" diff --git a/helpdesk_mgmt_crm/i18n/helpdesk_mgmt_crm.pot b/helpdesk_mgmt_crm/i18n/helpdesk_mgmt_crm.pot new file mode 100644 index 0000000000..60d40b8532 --- /dev/null +++ b/helpdesk_mgmt_crm/i18n/helpdesk_mgmt_crm.pot @@ -0,0 +1,120 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * helpdesk_mgmt_crm +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: helpdesk_mgmt_crm +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_view_form +msgid "Cancel" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.ticket_view_form +msgid "Convert to opportunity" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.actions.act_window,name:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_action +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_view_form +msgid "Create Lead" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.helpdesk_ticket_create_lead_view_form +msgid "Create opportunity" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__create_uid +msgid "Created by" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__create_date +msgid "Created on" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__display_name +msgid "Display Name" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model,name:helpdesk_mgmt_crm.model_helpdesk_ticket +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_crm_lead__ticket_id +msgid "Helpdesk Ticket" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model,name:helpdesk_mgmt_crm.model_helpdesk_ticket_create_lead +msgid "Helpdesk Ticket Create Lead" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__id +msgid "ID" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead____last_update +msgid "Last Modified on" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__write_date +msgid "Last Updated on" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model,name:helpdesk_mgmt_crm.model_crm_lead +msgid "Lead/Opportunity" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket__lead_count +msgid "Opportunity Count" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket__lead_ids +#: model_terms:ir.ui.view,arch_db:helpdesk_mgmt_crm.ticket_view_form +msgid "Opportunity(ies)" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__team_id +msgid "Team" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: code:addons/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead.py:0 +#, python-format +msgid "" +"This ticket has been converted to the opportunity %(name)s" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__ticket_id +msgid "Ticket" +msgstr "" + +#. module: helpdesk_mgmt_crm +#: model:ir.model.fields,field_description:helpdesk_mgmt_crm.field_helpdesk_ticket_create_lead__user_id +msgid "User" +msgstr "" diff --git a/helpdesk_mgmt_crm/models/__init__.py b/helpdesk_mgmt_crm/models/__init__.py new file mode 100644 index 0000000000..1126d8ab82 --- /dev/null +++ b/helpdesk_mgmt_crm/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import crm_lead +from . import helpdesk_ticket diff --git a/helpdesk_mgmt_crm/models/crm_lead.py b/helpdesk_mgmt_crm/models/crm_lead.py new file mode 100644 index 0000000000..34b1a9af53 --- /dev/null +++ b/helpdesk_mgmt_crm/models/crm_lead.py @@ -0,0 +1,12 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class CrmLead(models.Model): + _inherit = "crm.lead" + + ticket_id = fields.Many2one( + comodel_name="helpdesk.ticket", string="Helpdesk Ticket" + ) diff --git a/helpdesk_mgmt_crm/models/helpdesk_ticket.py b/helpdesk_mgmt_crm/models/helpdesk_ticket.py new file mode 100644 index 0000000000..14cf671cfc --- /dev/null +++ b/helpdesk_mgmt_crm/models/helpdesk_ticket.py @@ -0,0 +1,44 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class HelpdeskTicket(models.Model): + _inherit = "helpdesk.ticket" + + lead_ids = fields.One2many( + comodel_name="crm.lead", + inverse_name="ticket_id", + string="Opportunity(ies)", + ) + lead_count = fields.Integer( + compute="_compute_lead_count", string="Opportunity Count" + ) + + @api.depends("lead_ids") + def _compute_lead_count(self): + lead_data = self.env["crm.lead"].read_group( + [("ticket_id", "in", self.ids)], + ["ticket_id"], + ["ticket_id"], + ) + mapped_data = {t["ticket_id"][0]: t["ticket_id_count"] for t in lead_data} + for item in self: + item.lead_count = mapped_data.get(item.id, 0) + + def action_open_leads(self): + action = self.env.ref("crm.crm_lead_action_pipeline") + result = action.read()[0] + if len(self.lead_ids) == 1: + res = self.env.ref("crm.crm_lead_view_form", False) + result["views"] = [(res and res.id or False, "form")] + result["res_id"] = self.lead_ids.id + else: + result["domain"] = [("id", "in", self.lead_ids.ids)] + ctx = dict(self.env.context) + ctx.update( + {"default_ticket_id": self.id, "search_default_ticket_id": self.id} + ) + result["context"] = ctx + return result diff --git a/helpdesk_mgmt_crm/readme/CONTRIBUTORS.rst b/helpdesk_mgmt_crm/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..5d761f00a0 --- /dev/null +++ b/helpdesk_mgmt_crm/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + * Pilar Vargas diff --git a/helpdesk_mgmt_crm/readme/DESCRIPTION.rst b/helpdesk_mgmt_crm/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..7c6c768140 --- /dev/null +++ b/helpdesk_mgmt_crm/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows you to convert a helpdesk ticket into an opportunity, transferring its messages, +and keeping both linked. diff --git a/helpdesk_mgmt_crm/readme/USAGE.rst b/helpdesk_mgmt_crm/readme/USAGE.rst new file mode 100644 index 0000000000..990901eab4 --- /dev/null +++ b/helpdesk_mgmt_crm/readme/USAGE.rst @@ -0,0 +1,7 @@ +#. Go to *Helpdesk > Tickets* and create a new one or enter one. +#. Click on "Convert to opportunity" button. +#. A wizard will be displayed to set user and sales team if you want. +#. Click on "Create opportunity" button. +#. An opportunity will have been created with the ticket data and the messages will have been copied. +#. The related ticket will be displayed so you can return to it. +#. An "Opportunity(ies)" smart-button is also displayed on the ticket. diff --git a/helpdesk_mgmt_crm/security/ir.model.access.csv b/helpdesk_mgmt_crm/security/ir.model.access.csv new file mode 100644 index 0000000000..1579ef3645 --- /dev/null +++ b/helpdesk_mgmt_crm/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +helpdesk_mgmt_crm_salesman.access_helpdesk_ticket_create_lead,access_helpdesk_ticket_create_lead,helpdesk_mgmt_crm.model_helpdesk_ticket_create_lead,sales_team.group_sale_salesman,1,1,1,0 diff --git a/helpdesk_mgmt_crm/static/description/icon.png b/helpdesk_mgmt_crm/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/helpdesk_mgmt_crm/static/description/icon.png differ diff --git a/helpdesk_mgmt_crm/static/description/index.html b/helpdesk_mgmt_crm/static/description/index.html new file mode 100644 index 0000000000..5bbe2c671d --- /dev/null +++ b/helpdesk_mgmt_crm/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +Link between Helpdesk and CRM + + + + + + diff --git a/helpdesk_mgmt_crm/tests/__init__.py b/helpdesk_mgmt_crm/tests/__init__.py new file mode 100644 index 0000000000..ebb32f287d --- /dev/null +++ b/helpdesk_mgmt_crm/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_helpdesk_mgmt_crm diff --git a/helpdesk_mgmt_crm/tests/test_helpdesk_mgmt_crm.py b/helpdesk_mgmt_crm/tests/test_helpdesk_mgmt_crm.py new file mode 100644 index 0000000000..0b843d8c72 --- /dev/null +++ b/helpdesk_mgmt_crm/tests/test_helpdesk_mgmt_crm.py @@ -0,0 +1,77 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests import common +from odoo.tests.common import new_test_user, users + + +class TestHelpdeskMgmtCrm(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Mr Odoo"}) + cls.user = new_test_user( + cls.env, + login="sale-user", + groups="helpdesk_mgmt.group_helpdesk_user,sales_team.group_sale_salesman", + ) + cls.user2 = new_test_user( + cls.env, login="sale-user2", groups="sales_team.group_sale_salesman" + ) + cls.team = cls.env["crm.team"].create( + {"name": "Test team", "member_ids": [(6, 0, [cls.user2.id])]} + ) + cls.team.message_subscribe( + partner_ids=[cls.user2.partner_id.id], + ) + cls.ticket = cls.env["helpdesk.ticket"].create( + { + "name": "Test ticket", + "partner_id": cls.partner.id, + "user_id": cls.user.id, + "description": "Test description", + } + ) + + @users("sale-user") + def test_action_lead_create(self): + self.ticket.message_subscribe( + partner_ids=self.ticket.partner_id.ids, + subtype_ids=[self.env.ref("mail.mt_comment").id], + ) + # pylint: disable=translation-required + self.ticket.message_post(body="Ejemplo", subtype_xmlid="mail.mt_comment") + self.assertIn( + self.ticket.partner_id, + self.ticket.mapped("message_follower_ids.partner_id"), + ) + old_messages = self.ticket.message_ids + wizard = ( + self.env["helpdesk.ticket.create.lead"] + .with_context(active_id=self.ticket.id) + .create({"team_id": self.team.id}) + ) + res = wizard.action_helpdesk_ticket_to_lead() + self.assertTrue(self.ticket.lead_ids) + self.assertEqual(res["res_id"], self.ticket.lead_ids.id) + self.assertEqual(res["res_model"], self.ticket.lead_ids._name) + self.assertEqual(self.ticket.lead_ids.type, "opportunity") + self.assertEqual(self.ticket.name, self.ticket.lead_ids.name) + self.assertEqual(self.ticket.partner_id, self.ticket.lead_ids.partner_id) + self.assertEqual(self.ticket.user_id, self.ticket.lead_ids.user_id) + self.assertEqual(self.ticket.description, self.ticket.lead_ids.description) + self.assertGreater(len(self.ticket.lead_ids.message_ids), len(old_messages)) + self.assertGreater(len(self.ticket.message_ids), len(old_messages)) + self.assertIn( + self.user2.partner_id, + self.ticket.lead_ids.message_follower_ids.mapped("partner_id"), + ) + self.assertIn( + self.ticket.partner_id, + self.ticket.lead_ids.mapped("message_follower_ids.partner_id"), + ) + # action_open_lead + res = self.ticket.action_open_leads() + self.assertEqual(res["res_model"], self.ticket.lead_ids._name) + self.assertEqual(res["res_id"], self.ticket.lead_ids.id) diff --git a/helpdesk_mgmt_crm/views/crm_lead_view.xml b/helpdesk_mgmt_crm/views/crm_lead_view.xml new file mode 100644 index 0000000000..d44c1b03af --- /dev/null +++ b/helpdesk_mgmt_crm/views/crm_lead_view.xml @@ -0,0 +1,32 @@ + + + + + crm.lead.form + crm.lead + + + + + + + + + + crm.lead.search.lead + crm.lead + + + + + + + + + diff --git a/helpdesk_mgmt_crm/views/helpdesk_ticket_view.xml b/helpdesk_mgmt_crm/views/helpdesk_ticket_view.xml new file mode 100644 index 0000000000..415a1d6318 --- /dev/null +++ b/helpdesk_mgmt_crm/views/helpdesk_ticket_view.xml @@ -0,0 +1,52 @@ + + + + + helpdesk.ticket.view.search + helpdesk.ticket + + + + + + + + + + helpdesk.ticket.view.form + helpdesk.ticket + + + + + + + + + diff --git a/helpdesk_mgmt_crm/wizard/__init__.py b/helpdesk_mgmt_crm/wizard/__init__.py new file mode 100644 index 0000000000..831edaa2e0 --- /dev/null +++ b/helpdesk_mgmt_crm/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import helpdesk_ticket_create_lead diff --git a/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead.py b/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead.py new file mode 100644 index 0000000000..16b19e03d7 --- /dev/null +++ b/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead.py @@ -0,0 +1,63 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import SUPERUSER_ID, _, api, fields, models + + +class HelpdeskTicketCreateLead(models.TransientModel): + _name = "helpdesk.ticket.create.lead" + _description = "Helpdesk Ticket Create Lead" + + ticket_id = fields.Many2one( + comodel_name="helpdesk.ticket", + required=True, + readonly=True, + domain=[("lead_id", "=", False)], + ) + user_id = fields.Many2one(comodel_name="res.users") + team_id = fields.Many2one(comodel_name="crm.team") + + @api.model + def default_get(self, fields): + vals = super().default_get(fields) + ticket = self.env["helpdesk.ticket"].browse([self.env.context.get("active_id")]) + if ticket: + vals.update({"ticket_id": ticket.id}) + return vals + + def _prepare_vals(self): + return { + "ticket_id": self.ticket_id.id, + "name": self.ticket_id.name, + "partner_id": self.ticket_id.partner_id.id, + "user_id": self.user_id.id or self.ticket_id.user_id.id, + "team_id": self.team_id.id, + "description": self.ticket_id.description, + "type": "opportunity", + } + + def action_helpdesk_ticket_to_lead(self): + lead = self.env["crm.lead"].create(self._prepare_vals()) + for follower in self.ticket_id.message_follower_ids: + lead.message_subscribe( + partner_ids=[follower.partner_id.id], + subtype_ids=follower.subtype_ids.ids, + ) + self.ticket_id.write({"lead_ids": [(4, lead.id)]}) + for message in self.ticket_id.message_ids: + message.copy( + { + "model": lead._name, + "res_id": lead.id, + # prevent null value in column "notification_type" if message + # have notifications (not copied) + "notified_partner_ids": False, + } + ) + # Chatter reflects new Lead + body = _( + "This ticket has been converted to the opportunity " + "%(name)s" + ) % {"id": lead.id, "name": lead.name, "model": lead._name} + self.ticket_id.with_user(SUPERUSER_ID).message_post(body=body) + return lead.get_formview_action() diff --git a/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead_views.xml b/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead_views.xml new file mode 100644 index 0000000000..90936df566 --- /dev/null +++ b/helpdesk_mgmt_crm/wizard/helpdesk_ticket_create_lead_views.xml @@ -0,0 +1,31 @@ + + + + helpdesk.ticket.create.lead + helpdesk.ticket.create.lead + +
+ + + + + +
+
+
+
+
+ + Create Lead + helpdesk.ticket.create.lead + form + new + +
diff --git a/setup/helpdesk_mgmt_crm/odoo/addons/helpdesk_mgmt_crm b/setup/helpdesk_mgmt_crm/odoo/addons/helpdesk_mgmt_crm new file mode 120000 index 0000000000..0e2f4624aa --- /dev/null +++ b/setup/helpdesk_mgmt_crm/odoo/addons/helpdesk_mgmt_crm @@ -0,0 +1 @@ +../../../../helpdesk_mgmt_crm \ No newline at end of file diff --git a/setup/helpdesk_mgmt_crm/setup.py b/setup/helpdesk_mgmt_crm/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/helpdesk_mgmt_crm/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)