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 5fac8bc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 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
7 changes: 7 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,10 @@ 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.sudo().project_id.active = not lead.active
lead.sudo().project_id.analytic_account_id.active = not lead.active
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
35 changes: 34 additions & 1 deletion crm_project_create/tests/test_crm_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_crm_create_project(self):
)
)
self.assertEqual(wizard_form.project_name, self.lead.name)

wizard_form.project_name = "Test Project"
wizard_form.project_description = "Test Description"
wizard = wizard_form.save()
Expand All @@ -63,3 +62,37 @@ def test_crm_create_project(self):
self.lead.project_id.description,
Markup("<p>Test Description</p>"),
)

@users("user_salesman")
def test_crm_lead_archive(self):
"""When a lead is lost or achived, so it's project and their analytic account."""
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_form.project_name = "Test Project"
wizard_form.project_description = "Test Description"
wizard = wizard_form.save()
wizard.create_project()
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)
# Mark lead as lost
lost_wizard = self.env["crm.lead.lost"].create(
{
"lost_reason_id": self.env.ref("crm.lost_reason_1").id,
}
)
lost_wizard.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)

0 comments on commit 5fac8bc

Please sign in to comment.