Skip to content

Commit

Permalink
[T-6494][MIG]: crm_assign_project: migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tisho99 committed Sep 25, 2024
1 parent 39678be commit c4b941a
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 92 deletions.
79 changes: 0 additions & 79 deletions crm_assign_project/README.rst

This file was deleted.

Empty file modified crm_assign_project/__init__.py
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion crm_assign_project/__manifest__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "CRM Assign Project",
"summary": "Automatically assign project to CRM lead.",
"version": "12.0.1.0.0",
"version": "17.0.1.0.0",
"category": "CRM",
"website": "https://github.com/sygel-technology/sy-crm",
"author": "Sygel, Odoo Community Association (OCA)",
Expand Down
Empty file modified crm_assign_project/models/__init__.py
100755 → 100644
Empty file.
21 changes: 11 additions & 10 deletions crm_assign_project/models/crm_team.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class CrmTeam(models.Model):
Expand All @@ -15,25 +15,26 @@ class CrmTeam(models.Model):
comodel_name="project.project",
)

@api.multi
def write(self, vals):
values = super(CrmTeam, self).write(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.get_alias_values()
alias_values = self._alias_get_creation_values()
self.alias_id.write({"alias_defaults": alias_values["alias_defaults"]})
return values

def get_alias_values(self):
values = super(CrmTeam, self).get_alias_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"
).get("project_id"):
del values.get("alias_defaults")["project_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
5 changes: 5 additions & 0 deletions crm_assign_project/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 4 additions & 0 deletions crm_assign_project/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- 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>
1 change: 1 addition & 0 deletions crm_assign_project/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to automatically assign a project to a CRM lead when a lead/opportunity is created through an email.
1 change: 1 addition & 0 deletions crm_assign_project/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions crm_assign_project/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions crm_assign_project/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_crm_assign_project
73 changes: 73 additions & 0 deletions crm_assign_project/tests/test_crm_assign_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.crm.tests.common import TestCrmCommon
from odoo.tests.common import HttpCase, TransactionCase


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)
5 changes: 3 additions & 2 deletions crm_assign_project/views/crm_team_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<field name="model">crm.team</field>
<field name="inherit_id" ref="sales_team.crm_team_view_form" />
<field name="arch" type="xml">
<xpath expr="//group[@name='right']" position="inside">
<xpath expr="//sheet/group/group[@name='left']" position="inside">
<field name="automatic_project_assignation" />
<field
name="automatic_assignation_project_id"
attrs="{'invisible': [('automatic_project_assignation', '=', False)], 'required': [('automatic_project_assignation', '=', True)]}"
invisible="automatic_project_assignation==False"
required="automatic_project_assignation==True"
/>
</xpath>
</field>
Expand Down

0 comments on commit c4b941a

Please sign in to comment.