From 39c72d119cc9c3a7fc8d2a37d116b8ce172582ca Mon Sep 17 00:00:00 2001 From: Tobias Zehntner Date: Fri, 1 Oct 2021 09:48:11 +0200 Subject: [PATCH] [FIX] partner_multi_relation: Avoid access error on Relations button In Odoo v14, ir.actions.act_window have only access rights for admin while a user had read access in previous versions. Odoo provides now a function (_for_xml_id) that returns the action read with sudo. --- partner_multi_relation/models/res_partner.py | 4 +-- partner_multi_relation/tests/__init__.py | 1 + .../tests/test_partner_relation_action.py | 29 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 partner_multi_relation/tests/test_partner_relation_action.py diff --git a/partner_multi_relation/models/res_partner.py b/partner_multi_relation/models/res_partner.py index ab7b68972..59050c3db 100644 --- a/partner_multi_relation/models/res_partner.py +++ b/partner_multi_relation/models/res_partner.py @@ -187,9 +187,9 @@ class ResPartner(models.Model): ("other_partner_id", "=", contact.id), ] ) - action = self.env.ref( + action = self.env["ir.actions.act_window"]._for_xml_id( "partner_multi_relation.action_res_partner_relation_all" - ).read()[0] + ) action["domain"] = [("id", "in", relation_ids.ids)] context = action.get("context", "{}").strip()[1:-1] elements = context.split(",") if context else [] diff --git a/partner_multi_relation/tests/__init__.py b/partner_multi_relation/tests/__init__.py index a28c111cc..71685cafe 100644 --- a/partner_multi_relation/tests/__init__.py +++ b/partner_multi_relation/tests/__init__.py @@ -1,5 +1,6 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import test_partner_relation_common +from . import test_partner_relation_action from . import test_partner_relation from . import test_partner_relation_all from . import test_partner_search diff --git a/partner_multi_relation/tests/test_partner_relation_action.py b/partner_multi_relation/tests/test_partner_relation_action.py new file mode 100644 index 000000000..d8939c8ae --- /dev/null +++ b/partner_multi_relation/tests/test_partner_relation_action.py @@ -0,0 +1,29 @@ +# © 2021 Tobias Zehntner +# © 2021 Niboo SRL (https://www.niboo.com/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from odoo import exceptions + +from .test_partner_relation_common import TestPartnerRelationCommon + + +class TestPartnerRelationAction(TestPartnerRelationCommon): + def setUp(self): + super().setUp() + self.user = self.env["res.users"].create( + { + "login": "test_partner_action_user", + "name": "test_partner_action_user", + "groups_id": [ + (4, self.env.ref("base.group_user").id), + ], + } + ) + + def test_call_relation_action(self): + """Test calling relations action. Should be possible with simple user rights""" + try: + self.partner_01_person.with_user(self.user).action_view_relations() + except exceptions.AccessError: + self.fail("action_view_relations() raised AccessError unexpectedly!")