Skip to content

Commit

Permalink
[16.0][IMP] crm_project_create: Archive or reactive the project and i…
Browse files Browse the repository at this point in the history
…ts analytical account from lead.

@moduon MT-8265
  • Loading branch information
edlopen committed Jan 31, 2025
1 parent 619ddd4 commit 2aaebb9
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 40 deletions.
4 changes: 4 additions & 0 deletions crm_project_create/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ CRM Project Create
This module extends the functionality of crm and project and allow you
to create a project from opportunity or lead.

It also allows archiving or reactivating the project and its analytical
account from the lead.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
Expand Down Expand Up @@ -89,6 +92,7 @@ Contributors
------------

- Emilio Pascual (`Moduon <https://www.moduon.team/>`__)
- Eduardo López (`Moduon <https://www.moduon.team/>`__)

Maintainers
-----------
Expand Down
8 changes: 8 additions & 0 deletions crm_project_create/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ class CrmLead(models.Model):
_inherit = "crm.lead"

project_id = fields.Many2one("project.project", string="Project")

def toggle_active(self):
"""Archive or reactivate the project and their analytic account on lead toggle."""
for lead in self.filtered(lambda l: l.project_id):
lead_state = lead.active
lead.sudo().project_id.active = not lead_state
lead.sudo().project_id.analytic_account_id.active = not lead_state
return super().toggle_active()
1 change: 1 addition & 0 deletions crm_project_create/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Emilio Pascual ([Moduon](https://www.moduon.team/))
- Eduardo López ([Moduon](https://www.moduon.team/))
2 changes: 2 additions & 0 deletions crm_project_create/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
This module extends the functionality of crm and project and allow you to create a project from opportunity or lead.

It also allows archiving or reactivating the project and its analytical account from the lead.
14 changes: 7 additions & 7 deletions crm_project_create/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -372,6 +371,8 @@ <h1 class="title">CRM Project Create</h1>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/crm/tree/16.0/crm_project_create"><img alt="OCA/crm" src="https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/crm-16-0/crm-16-0-crm_project_create"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/crm&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of crm and project and allow you
to create a project from opportunity or lead.</p>
<p>It also allows archiving or reactivating the project and its analytical
account from the lead.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Expand Down Expand Up @@ -436,14 +437,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Emilio Pascual (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
<li>Eduardo López (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
Expand Down
2 changes: 2 additions & 0 deletions crm_project_create/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import common
from . import test_crm_create_project
from . import test_crm_lead
38 changes: 38 additions & 0 deletions crm_project_create/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2024 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)

from odoo.tests.common import TransactionCase

from odoo.addons.mail.tests.common import mail_new_test_user


class TestCrmLeadCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company = cls.env["res.company"].create(
{
"name": "Company Test",
}
)
cls.user_salesman = mail_new_test_user(
cls.env,
login="user_salesman",
name="User Salesman",
email="user_salesman@test.example.com",
company_id=cls.company.id,
groups="sales_team.group_sale_salesman",
)
cls.partner = cls.env["res.partner"].create(
{
"name": "Partner Test",
}
)
cls.lead = cls.env["crm.lead"].create(
{
"name": "Test Lead",
"type": "lead",
"partner_id": cls.partner.id,
"user_id": cls.user_salesman.id,
}
)
62 changes: 29 additions & 33 deletions crm_project_create/tests/test_crm_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,12 @@

from markupsafe import Markup

from odoo.tests.common import Form, TransactionCase, users
from odoo.tests.common import Form, users

from odoo.addons.mail.tests.common import mail_new_test_user
from .common import TestCrmLeadCommon


class TestCrmCreateProject(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company = cls.env["res.company"].create(
{
"name": "Company Test",
}
)
cls.user_salesman = mail_new_test_user(
cls.env,
login="user_salesman",
name="User Salesman",
email="user_salesman@test.example.com",
company_id=cls.company.id,
groups="sales_team.group_sale_salesman",
)
cls.partner = cls.env["res.partner"].create(
{
"name": "Partner Test",
}
)
cls.lead = cls.env["crm.lead"].create(
{
"name": "Test Lead",
"type": "lead",
"partner_id": cls.partner.id,
"user_id": cls.user_salesman.id,
}
)

class TestCrmCreateProject(TestCrmLeadCommon):
@users("user_salesman")
def test_crm_create_project(self):
"""Test the creation of a project from a lead."""
Expand All @@ -63,3 +33,29 @@ def test_crm_create_project(self):
self.lead.project_id.description,
Markup("<p>Test Description</p>"),
)

@users("user_salesman")
def test_crm_lead_lost(self):
"""Test when a lead is lost, the project and it's analytic account is
archived."""
wizard_form = Form(
self.env["crm.create.project"].with_context(
active_model="crm.lead",
active_id=self.lead.id,
default_lead_id=self.lead.id,
default_project_name=self.lead.name,
)
)
wizard = wizard_form.save()
wizard.create_project()
self.assertTrue(self.lead.project_id.active)
self.assertTrue(self.lead.project_id.analytic_account_id.active)

wizard_lost = self.env["crm.lead.lost"].create(
{
"lost_reason_id": self.env.ref("crm.lost_reason_1").id,
}
)
wizard_lost.with_context(active_ids=self.lead.ids).action_lost_reason_apply()
self.assertFalse(self.lead.project_id.active)
self.assertFalse(self.lead.project_id.analytic_account_id.active)
51 changes: 51 additions & 0 deletions crm_project_create/tests/test_crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2025 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)

from odoo.tests.common import Form, users

from .common import TestCrmLeadCommon


class TestCrmLead(TestCrmLeadCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
wizard_form = Form(
cls.env["crm.create.project"].with_context(
active_model="crm.lead",
active_id=cls.lead.id,
default_lead_id=cls.lead.id,
default_project_name=cls.lead.name,
)
)
wizard = wizard_form.save()
wizard.create_project()

@users("user_salesman")
def test_crm_lead_lost(self):
"""When a lead is lost, so it's project and their analytic account."""
self.assertTrue(self.lead.project_id.active)
self.assertTrue(self.lead.project_id.analytic_account_id.active)
# Use the cancel wizard to archive the lead
wizard_lost = self.env["crm.lead.lost"].create(
{
"lost_reason_id": self.env.ref("crm.lost_reason_1").id,
}
)
wizard_lost.with_context(active_ids=self.lead.ids).action_lost_reason_apply()
self.assertFalse(self.lead.project_id.active)
self.assertFalse(self.lead.project_id.analytic_account_id.active)

@users("user_salesman")
def test_crm_lead_archive(self):
"""When a lead is archived, so it's project and their analytic account.
And viceversa"""
self.assertTrue(self.lead.project_id.active)
self.assertTrue(self.lead.project_id.analytic_account_id.active)
self.lead.action_archive()
self.assertFalse(self.lead.project_id.active)
self.assertFalse(self.lead.project_id.analytic_account_id.active)
# Reactivate the lead
self.lead.toggle_active()
self.assertTrue(self.lead.project_id.active)
self.assertTrue(self.lead.project_id.analytic_account_id.active)

0 comments on commit 2aaebb9

Please sign in to comment.