diff --git a/crm_assign_project/README.rst b/crm_assign_project/README.rst new file mode 100644 index 0000000..8426da6 --- /dev/null +++ b/crm_assign_project/README.rst @@ -0,0 +1,89 @@ +================== +CRM Assign Project +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f12f92a7b3b43b634b25a7a9cfeb8d47e6e839783428e0a4f466c00ac654b700 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-sygel--technology%2Fsy--crm-lightgray.png?logo=github + :target: https://github.com/sygel-technology/sy-crm/tree/17.0/crm_assign_project + :alt: sygel-technology/sy-crm + +|badge1| |badge2| |badge3| + +This module allows to automatically assign a project to a CRM lead when +a lead/opportunity is created through an email. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +1. Go to CRM > Configuration > Sales Teams and select a team. +2. Check the 'Assign Project' checkbox +3. Select a value in 'Automatically Assigned Project' + +Usage +===== + +To usage this module, you need to: + +1. Create a new Lead, manually or sending a email to an alias, with a + Crm Team with a project_id +2. The created lead will have the configured project_id + +Known issues / Roadmap +====================== + +- Manually created leads with the fast creation popup wizard won't have + a default project_id, even if the user has a default team_id with a + default project_id. The reason is this is made with an onchange. + +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 +------- + +* Sygel + +Contributors +------------ + +- Harald Panten harald.panten@sygel.es +- Valentin Vinagre valentin.vinagre@sygel.es +- Alberto Martínez alberto.martinez@sygel.es +- Roger Sans roger.sans@sygel.es + +Maintainers +----------- + +This module is part of the `sygel-technology/sy-crm `_ project on GitHub. + +You are welcome to contribute. diff --git a/crm_assign_project/__init__.py b/crm_assign_project/__init__.py new file mode 100644 index 0000000..18143cb --- /dev/null +++ b/crm_assign_project/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/crm_assign_project/__manifest__.py b/crm_assign_project/__manifest__.py new file mode 100644 index 0000000..f6b8f03 --- /dev/null +++ b/crm_assign_project/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "CRM Assign Project", + "summary": "Automatically assign project to CRM lead.", + "version": "17.0.1.0.0", + "category": "CRM", + "website": "https://github.com/sygel-technology/sy-crm", + "author": "Sygel, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["crm", "sales_team", "crm_timesheet"], + "data": [ + "views/crm_team_views.xml", + ], +} diff --git a/crm_assign_project/i18n/es.po b/crm_assign_project/i18n/es.po new file mode 100644 index 0000000..bf90a1b --- /dev/null +++ b/crm_assign_project/i18n/es.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_assign_project +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-07-12 11:45+0000\n" +"PO-Revision-Date: 2022-07-12 13:45+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: es\n" +"X-Generator: Poedit 2.3\n" + +#. module: crm_assign_project +#: model:ir.model.fields,field_description:crm_assign_project.field_crm_team__automatic_project_assignation +msgid "Assign Project" +msgstr "Asignar proyecto" + +#. module: crm_assign_project +#: model:ir.model.fields,field_description:crm_assign_project.field_crm_team__automatic_assignation_project_id +msgid "Automatically Assigned Project" +msgstr "Proyecto asignado automáticamente" + +#. module: crm_assign_project +#: model:ir.model,name:crm_assign_project.model_crm_team +msgid "Sales Channels" +msgstr "Canales de Ventas" diff --git a/crm_assign_project/models/__init__.py b/crm_assign_project/models/__init__.py new file mode 100644 index 0000000..de73788 --- /dev/null +++ b/crm_assign_project/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import crm_team +from . import crm_lead diff --git a/crm_assign_project/models/crm_lead.py b/crm_assign_project/models/crm_lead.py new file mode 100644 index 0000000..d2e43ef --- /dev/null +++ b/crm_assign_project/models/crm_lead.py @@ -0,0 +1,17 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class CrmLead(models.Model): + _inherit = "crm.lead" + + @api.onchange("team_id") + def _onchange_team_id(self): + if ( + self.team_id + and self.team_id.automatic_project_assignation + and self.team_id.automatic_assignation_project_id + ): + self.project_id = self.team_id.automatic_assignation_project_id.id diff --git a/crm_assign_project/models/crm_team.py b/crm_assign_project/models/crm_team.py new file mode 100644 index 0000000..546d1f8 --- /dev/null +++ b/crm_assign_project/models/crm_team.py @@ -0,0 +1,40 @@ +# Copyright 2022 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class CrmTeam(models.Model): + _inherit = "crm.team" + + automatic_project_assignation = fields.Boolean( + string="Assign Project", default=False + ) + automatic_assignation_project_id = fields.Many2one( + string="Automatically Assigned Project", + comodel_name="project.project", + ) + + def write(self, vals): + values = super().write(vals) + if ( + "automatic_project_assignation" in vals + or "automatic_assignation_project_id" in vals + ) and self.alias_id: + alias_values = self._alias_get_creation_values() + self.alias_id.write({"alias_defaults": alias_values["alias_defaults"]}) + return values + + def _alias_get_creation_values(self): + values = super()._alias_get_creation_values() + if self.automatic_project_assignation and self.automatic_assignation_project_id: + values["alias_defaults"][ + "project_id" + ] = self.automatic_assignation_project_id.id + elif ( + not self.automatic_project_assignation + and values.get("alias_defaults") + and values.get("alias_defaults").get("project_id") + ): + values.get("alias_defaults").pop("project_id") + return values diff --git a/crm_assign_project/pyproject.toml b/crm_assign_project/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/crm_assign_project/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/crm_assign_project/readme/CONFIGURE.md b/crm_assign_project/readme/CONFIGURE.md new file mode 100755 index 0000000..a80379a --- /dev/null +++ b/crm_assign_project/readme/CONFIGURE.md @@ -0,0 +1,5 @@ +To configure this module, you need to: + +1. Go to CRM > Configuration > Sales Teams and select a team. +2. Check the 'Assign Project' checkbox +3. Select a value in 'Automatically Assigned Project' diff --git a/crm_assign_project/readme/CONTRIBUTORS.md b/crm_assign_project/readme/CONTRIBUTORS.md new file mode 100755 index 0000000..0cb824c --- /dev/null +++ b/crm_assign_project/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Harald Panten +- Valentin Vinagre +- Alberto Martínez +- Roger Sans diff --git a/crm_assign_project/readme/DESCRIPTION.md b/crm_assign_project/readme/DESCRIPTION.md new file mode 100755 index 0000000..a7f7950 --- /dev/null +++ b/crm_assign_project/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to automatically assign a project to a CRM lead when a lead/opportunity is created through an email. diff --git a/crm_assign_project/readme/ROADMAP.md b/crm_assign_project/readme/ROADMAP.md new file mode 100755 index 0000000..00d4bb5 --- /dev/null +++ b/crm_assign_project/readme/ROADMAP.md @@ -0,0 +1 @@ +- Manually created leads with the fast creation popup wizard won't have a default project_id, even if the user has a default team_id with a default project_id. The reason is this is made with an onchange. diff --git a/crm_assign_project/readme/USAGE.md b/crm_assign_project/readme/USAGE.md new file mode 100755 index 0000000..924b414 --- /dev/null +++ b/crm_assign_project/readme/USAGE.md @@ -0,0 +1,4 @@ +To usage this module, you need to: + +1. Create a new Lead, manually or sending a email to an alias, with a Crm Team with a project_id +2. The created lead will have the configured project_id diff --git a/crm_assign_project/static/description/icon.png b/crm_assign_project/static/description/icon.png new file mode 100644 index 0000000..207fb7a Binary files /dev/null and b/crm_assign_project/static/description/icon.png differ diff --git a/crm_assign_project/static/description/index.html b/crm_assign_project/static/description/index.html new file mode 100644 index 0000000..da50f02 --- /dev/null +++ b/crm_assign_project/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +CRM Assign Project + + + +
+

CRM Assign Project

+ + +

Beta License: AGPL-3 sygel-technology/sy-crm

+

This module allows to automatically assign a project to a CRM lead when +a lead/opportunity is created through an email.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to CRM > Configuration > Sales Teams and select a team.
  2. +
  3. Check the ‘Assign Project’ checkbox
  4. +
  5. Select a value in ‘Automatically Assigned Project’
  6. +
+
+
+

Usage

+

To usage this module, you need to:

+
    +
  1. Create a new Lead, manually or sending a email to an alias, with a +Crm Team with a project_id
  2. +
  3. The created lead will have the configured project_id
  4. +
+
+
+

Known issues / Roadmap

+
    +
  • Manually created leads with the fast creation popup wizard won’t have +a default project_id, even if the user has a default team_id with a +default project_id. The reason is this is made with an onchange.
  • +
+
+
+

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

+
    +
  • Sygel
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the sygel-technology/sy-crm project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/crm_assign_project/tests/__init__.py b/crm_assign_project/tests/__init__.py new file mode 100644 index 0000000..d8cc267 --- /dev/null +++ b/crm_assign_project/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_crm_assign_project diff --git a/crm_assign_project/tests/test_crm_assign_project.py b/crm_assign_project/tests/test_crm_assign_project.py new file mode 100644 index 0000000..872b915 --- /dev/null +++ b/crm_assign_project/tests/test_crm_assign_project.py @@ -0,0 +1,77 @@ +# Copyright 2024 Alberto Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo.addons.crm.tests.common import TestCrmCommon + +INCOMING_EMAIL = """Return-Path: {return_path} +X-Original-To: {to} +Delivered-To: {to} +Received: by mail.my.com (Postfix, from userid xxx) + id 822ECBFB67; Mon, 24 Oct 2011 07:36:51 +0200 (CEST) +X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.my.com +X-Spam-Level: +X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham + version=3.3.1 +Received: from [192.168.1.146] + (Authenticated sender: {email_from}) + by mail.customer.com (Postfix) with ESMTPSA id 07A30BFAB4 + for <{to}>; Mon, 24 Oct 2011 07:36:50 +0200 (CEST) +Message-ID: {msg_id} +Date: Mon, 24 Oct 2011 11:06:29 +0530 +From: {email_from} +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) + Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 +MIME-Version: 1.0 +To: {to} +Subject: {subject} +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 8bit + +This is an example email. All sensitive content has been stripped out. + +ALL GLORY TO THE HYPNOTOAD! + +Cheers, + +Somebody.""" + + +class TestCrmAssignProject(TestCrmCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.test_project_id = cls.env["project.project"].create( + {"name": "Test Mail Project"} + ) + cls.sales_team_1.write( + { + "automatic_project_assignation": True, + "automatic_assignation_project_id": cls.test_project_id.id, + } + ) + + def test_mail_crm_assign_project(self): + new_lead = self.format_and_process( + INCOMING_EMAIL, + "unknown.sender@test.example.com", + self.sales_team_1.alias_email, + subject="Delivery cost inquiry", + target_model="crm.lead", + ) + self.assertEqual(new_lead.project_id.id, self.test_project_id.id) + + def test_mail_crm_no_assign_project(self): + self.sales_team_1.write( + { + "automatic_project_assignation": False, + } + ) + new_lead = self.format_and_process( + INCOMING_EMAIL, + "unknown.sender@test.example.com", + self.sales_team_1.alias_email, + subject="Delivery cost inquiry", + target_model="crm.lead", + ) + self.assertEqual(new_lead.project_id.id, False) diff --git a/crm_assign_project/views/crm_team_views.xml b/crm_assign_project/views/crm_team_views.xml new file mode 100644 index 0000000..36d5280 --- /dev/null +++ b/crm_assign_project/views/crm_team_views.xml @@ -0,0 +1,20 @@ + + + + + crm.mail.automatic.activity.team.view.form + crm.team + + + + + + + + +