diff --git a/partner_stage/README.rst b/partner_stage/README.rst index 427777f322e9..ddc528e36166 100644 --- a/partner_stage/README.rst +++ b/partner_stage/README.rst @@ -72,6 +72,8 @@ Contributors - Maksym Yankin maksym.yankin@camptocamp.com +- Bert Van Groenendael + Maintainers ----------- diff --git a/partner_stage/readme/CONTRIBUTORS.md b/partner_stage/readme/CONTRIBUTORS.md index 43a0e032f234..053025a6784f 100644 --- a/partner_stage/readme/CONTRIBUTORS.md +++ b/partner_stage/readme/CONTRIBUTORS.md @@ -3,3 +3,5 @@ * `Camptocamp `__: * Maksym Yankin + +- Bert Van Groenendael \<\> diff --git a/partner_stage/security/ir.model.access.csv b/partner_stage/security/ir.model.access.csv index a8c5a47e1129..8dde3cfefb47 100644 --- a/partner_stage/security/ir.model.access.csv +++ b/partner_stage/security/ir.model.access.csv @@ -1,3 +1,3 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_partner_stage_edit","access_partner_stage_edit","model_res_partner_stage","base.group_system",1,1,1,1 -"access_partner_stage_read","access_partner_stage_read","model_res_partner_stage",,1,0,0,0 +"access_partner_stage_read","access_partner_stage_read","model_res_partner_stage","base.group_user",1,0,0,0 diff --git a/partner_stage/static/description/index.html b/partner_stage/static/description/index.html index 47f7e19cf38f..55186d9f92c8 100644 --- a/partner_stage/static/description/index.html +++ b/partner_stage/static/description/index.html @@ -416,6 +416,7 @@

Contributors

  • Maksym Yankin maksym.yankin@camptocamp.com
  • +
  • Bert Van Groenendael <bert.vangroenendael@dynapps.eu>
  • diff --git a/partner_stage/tests/test_partner_stage.py b/partner_stage/tests/test_partner_stage.py index 6c6eff0b5910..fc99fd58c2bf 100644 --- a/partner_stage/tests/test_partner_stage.py +++ b/partner_stage/tests/test_partner_stage.py @@ -1,9 +1,10 @@ # Copyright 2021 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase +from .. import post_init_hook + class TestPartnerStage(TransactionCase): @classmethod @@ -12,13 +13,66 @@ def setUpClass(cls): cls.Stage = cls.env["res.partner.stage"] cls.Partner = cls.env["res.partner"] - def test_01_partner_stage(self): + # Create some test partners without a stage + cls.partner_1 = cls.env["res.partner"].create( + { + "name": "Partner 1", + "stage_id": False, + } + ) + cls.partner_2 = cls.env["res.partner"].create( + { + "name": "Partner 2", + "stage_id": False, + } + ) + + def test_01_post_init_hook(self): + """Test post_init_hook sets the default stage on partners without stage_id""" + + # Ensure partners initially have no stage + self.assertFalse(self.partner_1.stage_id) + self.assertFalse(self.partner_2.stage_id) + + post_init_hook(self.env) + + # Reload the partners from the database to get the updated values + self.partner_1.invalidate_recordset() + self.partner_2.invalidate_recordset() + + # Check if partners' stages have been updated + self.assertEqual( + self.partner_1.stage_id, self.env.ref("partner_stage.partner_stage_active") + ) + self.assertEqual( + self.partner_2.stage_id, self.env.ref("partner_stage.partner_stage_active") + ) + self.assertEqual(self.partner_1.stage_id.state, "confirmed") + self.assertEqual(self.partner_2.stage_id.state, "confirmed") + + post_init_hook(self.env) + + # Reload the partners from the database to get the updated values + self.partner_1.invalidate_recordset() + self.partner_2.invalidate_recordset() + + # Check if partners' stages have been updated + self.assertEqual( + self.partner_1.stage_id, self.env.ref("partner_stage.partner_stage_active") + ) + self.assertEqual( + self.partner_2.stage_id, self.env.ref("partner_stage.partner_stage_active") + ) + self.assertEqual(self.partner_1.stage_id.state, "confirmed") + self.assertEqual(self.partner_2.stage_id.state, "confirmed") + + def test_02_partner_stage(self): default_stage = self.env.ref("partner_stage.partner_stage_active") new_partner = self.Partner.create({"name": "A Partner"}) self.assertTrue(new_partner.stage_id, default_stage) states = new_partner._read_group_stage_id(self.Stage, [], None) self.assertTrue(states.ids, [1, 2, 3]) - def test_02_stage_default_constraint(self): + def test_03_stage_default_constraint(self): with self.assertRaises(ValidationError): self.Stage.create({"name": "Another Default Stage", "is_default": True}) diff --git a/partner_stage/views/res_partner_stage_views.xml b/partner_stage/views/res_partner_stage_views.xml index 2ddb021bf432..abb062fb2bb2 100644 --- a/partner_stage/views/res_partner_stage_views.xml +++ b/partner_stage/views/res_partner_stage_views.xml @@ -31,20 +31,20 @@ res.partner.stage - + - + Stage res.partner.stage - tree,form + list,form