Skip to content

Commit 6794b09

Browse files
[MIG] base_model_restrict_update: Migration to 19.0
1 parent e95b16e commit 6794b09

File tree

6 files changed

+49
-31
lines changed

6 files changed

+49
-31
lines changed

base_model_restrict_update/README.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ Update Restrict Model
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-tools/tree/18.0/base_model_restrict_update
24+
:target: https://github.com/OCA/server-tools/tree/19.0/base_model_restrict_update
2525
:alt: OCA/server-tools
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_model_restrict_update
27+
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-base_model_restrict_update
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
3434

3535
This module adds the following features:
3636

37-
- The ability to limit the update permissions for a model to certain
38-
groups
39-
- The ability to revoke update permissions for specific users
37+
- The ability to limit the update permissions for a model to certain
38+
groups
39+
- The ability to revoke update permissions for specific users
4040

4141
**Table of contents**
4242

@@ -69,7 +69,7 @@ Bug Tracker
6969
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
7070
In case of trouble, please check there if your issue has already been reported.
7171
If you spotted it first, help us to smash it by providing a detailed and welcomed
72-
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_model_restrict_update%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
72+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_model_restrict_update%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7373

7474
Do not contact contributors directly about support or help with technical issues.
7575

@@ -84,19 +84,19 @@ Authors
8484
Contributors
8585
------------
8686

87-
- `Quartile <https://www.quartile.co>`__:
87+
- `Quartile <https://www.quartile.co>`__:
8888

89-
- Yoshi Tashiro <[email protected]>
89+
- Yoshi Tashiro <[email protected]>
9090

91-
- Ecosoft
91+
- Ecosoft
9292

93-
- Kitti U. <[email protected]>
93+
- Kitti U. <[email protected]>
9494

9595
Other credits
9696
-------------
9797

98-
- This module borrows the idea from 'Moises Lopez
99-
<https://odoo-community.org/groups/contributors-15/contributors-161807>'
98+
- This module borrows the idea from 'Moises Lopez
99+
<https://odoo-community.org/groups/contributors-15/contributors-161807>'
100100

101101
Maintainers
102102
-----------
@@ -122,6 +122,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
122122

123123
|maintainer-yostashiro| |maintainer-aungkokolin1997|
124124

125-
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/base_model_restrict_update>`_ project on GitHub.
125+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/base_model_restrict_update>`_ project on GitHub.
126126

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

base_model_restrict_update/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
33
{
44
"name": "Update Restrict Model",
5-
"version": "18.0.1.0.0",
5+
"version": "19.0.1.0.0",
66
"depends": ["base_setup"],
77
"website": "https://github.com/OCA/server-tools",
88
"author": "Odoo Community Association (OCA), Quartile",

base_model_restrict_update/models/ir_model_access.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from odoo import api, models
55
from odoo.exceptions import AccessError
6-
from odoo.tools.translate import _
76

87

98
class IrModelAccess(models.Model):
@@ -72,7 +71,10 @@ def check(self, model, mode="read", raise_exception=True):
7271
if not raise_exception:
7372
return False
7473
raise AccessError(
75-
_("You are only allowed to read this record. (%(model)s - %(mode)s)")
76-
% {"model": model, "mode": mode}
74+
self.env._(
75+
"You are only allowed to read this record. (%(model)s - %(mode)s)"
76+
),
77+
model=model,
78+
mode=mode,
7779
)
7880
return res

base_model_restrict_update/models/res_users.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2021-2024 Quartile (https://www.quartile.co)
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
33

4-
from odoo import _, api, fields, models
4+
from odoo import api, fields, models
55
from odoo.exceptions import UserError
66

77

@@ -14,8 +14,11 @@ class ResUsers(models.Model):
1414
"records.",
1515
)
1616

17-
@api.constrains("is_readonly_user", "groups_id")
17+
@api.constrains("is_readonly_user", "group_ids")
1818
def _check_is_readonly_user(self):
1919
for user in self:
20-
if user.has_group("base.group_system") and user.is_readonly_user:
21-
raise UserError(_("You cannot make the admin user read-only."))
20+
if (
21+
user in self.env.ref("base.group_system").user_ids
22+
and user.is_readonly_user
23+
):
24+
raise UserError(self.env._("You cannot make the admin user read-only."))

base_model_restrict_update/static/description/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Update Restrict Model</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:a0a6bc8d798dea0412aeb5e7c9f5fe8f7aec4d6d0e40c7e0d2c19ffc07bbb2cb
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/base_model_restrict_update"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_model_restrict_update"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/19.0/base_model_restrict_update"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-base_model_restrict_update"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module adds the following features:</p>
379379
<ul class="simple">
380380
<li>The ability to limit the update permissions for a model to certain
@@ -420,7 +420,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
420420
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
421421
In case of trouble, please check there if your issue has already been reported.
422422
If you spotted it first, help us to smash it by providing a detailed and welcomed
423-
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_model_restrict_update%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
423+
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_model_restrict_update%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
424424
<p>Do not contact contributors directly about support or help with technical issues.</p>
425425
</div>
426426
<div class="section" id="credits">
@@ -462,7 +462,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
462462
promote its widespread use.</p>
463463
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
464464
<p><a class="reference external image-reference" href="https://github.com/yostashiro"><img alt="yostashiro" src="https://github.com/yostashiro.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/aungkokolin1997"><img alt="aungkokolin1997" src="https://github.com/aungkokolin1997.png?size=40px" /></a></p>
465-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/18.0/base_model_restrict_update">OCA/server-tools</a> project on GitHub.</p>
465+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/19.0/base_model_restrict_update">OCA/server-tools</a> project on GitHub.</p>
466466
<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>
467467
</div>
468468
</div>

base_model_restrict_update/tests/test_base_model_restrict_update.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@ def setUpClass(cls):
1515
cls.group_partner_update = cls.env["res.groups"].create(
1616
{"name": "Partner Update Group"}
1717
)
18-
cls.test_user = cls.env["res.users"].create({"name": "test", "login": "test"})
18+
cls.test_user = cls.env["res.users"].create(
19+
{
20+
"name": "test",
21+
"login": "test",
22+
"group_ids": [
23+
Command.set(
24+
[
25+
cls.env.ref("base.group_user").id,
26+
cls.env.ref("base.group_partner_manager").id,
27+
]
28+
)
29+
],
30+
}
31+
)
1932
cls.partner_model_with_test_user = cls.env["res.partner"].with_user(
2033
cls.test_user.id
2134
)
@@ -43,7 +56,7 @@ def test_with_model_restriction(self):
4356
self.test_partner_with_test_user.write({"name": "baz"})
4457
with self.assertRaises(AccessError):
4558
self.test_partner_with_test_user.unlink()
46-
self.test_user.groups_id = [Command.link(self.group_partner_update.id)]
59+
self.test_user.group_ids = [Command.link(self.group_partner_update.id)]
4760
self.partner_model_with_test_user.create({"name": "bar"})
4861
self.test_partner_with_test_user.write({"name": "baz"})
4962
self.test_partner_with_test_user.unlink()
@@ -59,7 +72,7 @@ def test_with_user_readonly(self):
5972
# To confirm that is_readonly_user prevails
6073
self.model_partner.restrict_update = True
6174
self.model_partner.update_allowed_group_ids = self.group_partner_update
62-
self.test_user.groups_id = [Command.link(self.group_partner_update.id)]
75+
self.test_user.group_ids = [Command.link(self.group_partner_update.id)]
6376
with self.assertRaises(AccessError):
6477
self.partner_model_with_test_user.create({"name": "bar"})
6578
with self.assertRaises(AccessError):
@@ -82,10 +95,10 @@ def test_with_user_readonly(self):
8295

8396
def test_set_user_readonly(self):
8497
group_system_id = self.env.ref("base.group_system").id
85-
self.test_user.groups_id = [Command.link(group_system_id)]
98+
self.test_user.group_ids = [Command.link(group_system_id)]
8699
with self.assertRaises(UserError):
87100
self.test_user.is_readonly_user = True
88-
self.test_user.groups_id = [Command.unlink(group_system_id)]
101+
self.test_user.group_ids = [Command.unlink(group_system_id)]
89102
self.test_user.is_readonly_user = True
90103
with self.assertRaises(UserError):
91-
self.test_user.groups_id = [Command.link(group_system_id)]
104+
self.test_user.group_ids = [Command.link(group_system_id)]

0 commit comments

Comments
 (0)