From 62dba28c2b27172b7ef99225052dba8c0725a775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 7 Jun 2024 17:26:42 +0200 Subject: [PATCH 1/2] [FIX] crm_won_restrict_per_stage: Add ValidationError to onchange to prevent display incorrect UX changes TT49558 --- crm_won_restrict_per_stage/models/crm_lead.py | 19 ++++++++++++++++++- .../tests/test_crm_lead.py | 9 ++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crm_won_restrict_per_stage/models/crm_lead.py b/crm_won_restrict_per_stage/models/crm_lead.py index 2bf7ddea3ce..6210f2f7b41 100644 --- a/crm_won_restrict_per_stage/models/crm_lead.py +++ b/crm_won_restrict_per_stage/models/crm_lead.py @@ -1,7 +1,7 @@ # Copyright 2024 Tecnativa - Carolina Fernandez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) -from odoo import _, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -10,6 +10,23 @@ class CrmStage(models.Model): show_won_button = fields.Boolean(related="stage_id.show_won_button") + @api.onchange("stage_id") + def _onchange_stage_id(self): + """Do it this way for avoiding a UI glitch if we let act + the exception in the write, as the stage is changed in the + interface, but the message appears and the record is kept + unsaved. + """ + for item in self: + if ( + item != item._origin + and item.stage_id.is_won + and not item._origin.stage_id.show_won_button + ): + raise ValidationError( + _("You can't change to this stage from the current stage.") + ) + def write(self, vals): for rec in self: if vals.get("stage_id"): diff --git a/crm_won_restrict_per_stage/tests/test_crm_lead.py b/crm_won_restrict_per_stage/tests/test_crm_lead.py index 85b9e3e0f56..0359e351862 100644 --- a/crm_won_restrict_per_stage/tests/test_crm_lead.py +++ b/crm_won_restrict_per_stage/tests/test_crm_lead.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) from odoo.exceptions import ValidationError +from odoo.tests import Form from odoo.tests.common import TransactionCase @@ -13,11 +14,17 @@ def setUpClass(cls): cls.stage_new = cls.env.ref("crm.stage_lead1") cls.stage_won = cls.env.ref("crm.stage_lead4") - def test_change_crm_stage_won_without_show_button(self): + def test_change_crm_stage_won_without_show_button_01(self): self.stage_new.show_won_button = False with self.assertRaises(ValidationError): self.crm_lead.stage_id = self.stage_won + def test_change_crm_stage_won_without_show_button_02(self): + self.stage_new.show_won_button = False + lead_form = Form(self.crm_lead) + with self.assertRaises(ValidationError): + lead_form.stage_id = self.stage_won + def test_change_crm_stage_to_won_with_show_button(self): self.stage_new.show_won_button = True self.crm_lead.stage_id = self.stage_won From 8d8cb69c98b640c378bd56397f6002e2997c253f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 10 Jun 2024 08:08:35 +0200 Subject: [PATCH 2/2] [FIX] crm_won_restrict_per_stage: Define the correct maintainer in the __manifest__ TT49558 --- crm_won_restrict_per_stage/README.rst | 8 ++++---- crm_won_restrict_per_stage/__manifest__.py | 2 +- crm_won_restrict_per_stage/static/description/index.html | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crm_won_restrict_per_stage/README.rst b/crm_won_restrict_per_stage/README.rst index b22a3dba7ad..af2d3c8a724 100644 --- a/crm_won_restrict_per_stage/README.rst +++ b/crm_won_restrict_per_stage/README.rst @@ -90,13 +90,13 @@ 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. -.. |maintainer-carolina-fernandez| image:: https://github.com/carolina-fernandez.png?size=40px - :target: https://github.com/carolina-fernandez - :alt: carolina-fernandez +.. |maintainer-carolinafernandez-tecnativa| image:: https://github.com/carolinafernandez-tecnativa.png?size=40px + :target: https://github.com/carolinafernandez-tecnativa + :alt: carolinafernandez-tecnativa Current `maintainer `__: -|maintainer-carolina-fernandez| +|maintainer-carolinafernandez-tecnativa| This module is part of the `OCA/crm `_ project on GitHub. diff --git a/crm_won_restrict_per_stage/__manifest__.py b/crm_won_restrict_per_stage/__manifest__.py index 16282439467..29dabb83256 100644 --- a/crm_won_restrict_per_stage/__manifest__.py +++ b/crm_won_restrict_per_stage/__manifest__.py @@ -11,5 +11,5 @@ "depends": ["crm"], "data": ["views/crm_lead_views.xml", "views/crm_stage_views.xml"], "installable": True, - "maintainers": ["carolina-fernandez"], + "maintainers": ["carolinafernandez-tecnativa"], } diff --git a/crm_won_restrict_per_stage/static/description/index.html b/crm_won_restrict_per_stage/static/description/index.html index fd749f757d7..522f7a37c06 100644 --- a/crm_won_restrict_per_stage/static/description/index.html +++ b/crm_won_restrict_per_stage/static/description/index.html @@ -1,4 +1,3 @@ - @@ -435,7 +434,7 @@

Maintainers

mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

-

carolina-fernandez

+

carolinafernandez-tecnativa

This module is part of the OCA/crm project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.