diff --git a/crm_project_create/README.rst b/crm_project_create/README.rst index a28e3b39f12..03996128b4a 100644 --- a/crm_project_create/README.rst +++ b/crm_project_create/README.rst @@ -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. @@ -89,6 +92,7 @@ Contributors ------------ - Emilio Pascual (`Moduon `__) +- Eduardo López (`Moduon `__) Maintainers ----------- diff --git a/crm_project_create/models/crm_lead.py b/crm_project_create/models/crm_lead.py index 7bbd73a44ac..eaf550d43a7 100644 --- a/crm_project_create/models/crm_lead.py +++ b/crm_project_create/models/crm_lead.py @@ -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() diff --git a/crm_project_create/readme/CONTRIBUTORS.md b/crm_project_create/readme/CONTRIBUTORS.md index ee7b9a6c8ba..a04bd695190 100644 --- a/crm_project_create/readme/CONTRIBUTORS.md +++ b/crm_project_create/readme/CONTRIBUTORS.md @@ -1 +1,2 @@ - Emilio Pascual ([Moduon](https://www.moduon.team/)) +- Eduardo López ([Moduon](https://www.moduon.team/)) diff --git a/crm_project_create/readme/DESCRIPTION.md b/crm_project_create/readme/DESCRIPTION.md index bff2e47626f..9d1f31ce375 100644 --- a/crm_project_create/readme/DESCRIPTION.md +++ b/crm_project_create/readme/DESCRIPTION.md @@ -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. diff --git a/crm_project_create/static/description/index.html b/crm_project_create/static/description/index.html index edc33d01cfe..1985ff03a67 100644 --- a/crm_project_create/static/description/index.html +++ b/crm_project_create/static/description/index.html @@ -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. @@ -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 } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -372,6 +371,8 @@

CRM Project Create

Alpha License: LGPL-3 OCA/crm Translate me on Weblate Try me on Runboat

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. @@ -436,14 +437,13 @@

Authors

Contributors

Maintainers

This module is maintained by the OCA.

- -Odoo Community Association - +Odoo Community Association

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.

diff --git a/crm_project_create/tests/test_crm_create_project.py b/crm_project_create/tests/test_crm_create_project.py index 4674742000c..b7e41e9fc67 100644 --- a/crm_project_create/tests/test_crm_create_project.py +++ b/crm_project_create/tests/test_crm_create_project.py @@ -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() @@ -63,3 +62,37 @@ def test_crm_create_project(self): self.lead.project_id.description, Markup("

Test Description

"), ) + + @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)