Skip to content

Commit

Permalink
Merge PR #569 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jun 10, 2024
2 parents 3b214d0 + 8d8cb69 commit 3567e7b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
8 changes: 4 additions & 4 deletions crm_won_restrict_per_stage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-carolina-fernandez|
|maintainer-carolinafernandez-tecnativa|

This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/16.0/crm_won_restrict_per_stage>`_ project on GitHub.

Expand Down
2 changes: 1 addition & 1 deletion crm_won_restrict_per_stage/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}
19 changes: 18 additions & 1 deletion crm_won_restrict_per_stage/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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"):
Expand Down
3 changes: 1 addition & 2 deletions crm_won_restrict_per_stage/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -435,7 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/carolina-fernandez"><img alt="carolina-fernandez" src="https://github.com/carolina-fernandez.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/carolinafernandez-tecnativa"><img alt="carolinafernandez-tecnativa" src="https://github.com/carolinafernandez-tecnativa.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/crm/tree/16.0/crm_won_restrict_per_stage">OCA/crm</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
9 changes: 8 additions & 1 deletion crm_won_restrict_per_stage/tests/test_crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down

0 comments on commit 3567e7b

Please sign in to comment.