Skip to content

Commit c4b52ef

Browse files
Milan Topuzovclement-gouin
authored andcommitted
[MIG] base_user_role_company: Migration to 19.0
1 parent 64dbfc6 commit c4b52ef

11 files changed

Lines changed: 111 additions & 71 deletions

File tree

base_user_role_company/README.rst

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
=====================
26
User roles by company
37
=====================
@@ -13,17 +17,17 @@ User roles by company
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github
20-
:target: https://github.com/OCA/server-backend/tree/18.0/base_user_role_company
24+
:target: https://github.com/OCA/server-backend/tree/19.0/base_user_role_company
2125
:alt: OCA/server-backend
2226
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-base_user_role_company
27+
:target: https://translation.odoo-community.org/projects/server-backend-19-0/server-backend-19-0-base_user_role_company
2428
:alt: Translate me on Weblate
2529
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=19.0
2731
:alt: Try me on Runboat
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -66,29 +70,29 @@ to all active companies will be activated.
6670

6771
For example:
6872

69-
- A "SALES PERSON" and a "SALES MANAGER" roles are created.
73+
- A "SALES PERSON" and a "SALES MANAGER" roles are created.
7074

71-
- A user is assigned to the roles:
75+
- A user is assigned to the roles:
7276

73-
- "SALES PERSON", with no specific company assigned (meaning all)
74-
- "SALES MANAGER" only to "My Company (Chicago)"
77+
- "SALES PERSON", with no specific company assigned (meaning all)
78+
- "SALES MANAGER" only to "My Company (Chicago)"
7579

76-
- When selecting active companies from the UI widget:
80+
- When selecting active companies from the UI widget:
7781

78-
- If only "My Company (San Francisco)" is active, "SALES PERSON" will
79-
be active.
80-
- If only "My Company (Chicago)" is active, "SALES PERSON" and "SALES
81-
MANAGER" will be active.
82-
- If both "My Company (San Francisco)" and "My Company (Chicago)" is
83-
active, "SALES PERSON" will be active.
82+
- If only "My Company (San Francisco)" is active, "SALES PERSON"
83+
will be active.
84+
- If only "My Company (Chicago)" is active, "SALES PERSON" and
85+
"SALES MANAGER" will be active.
86+
- If both "My Company (San Francisco)" and "My Company (Chicago)" is
87+
active, "SALES PERSON" will be active.
8488

8589
Bug Tracker
8690
===========
8791

8892
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/issues>`_.
8993
In case of trouble, please check there if your issue has already been reported.
9094
If you spotted it first, help us to smash it by providing a detailed and welcomed
91-
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_user_role_company%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
95+
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_user_role_company%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
9296

9397
Do not contact contributors directly about support or help with technical issues.
9498

@@ -105,17 +109,17 @@ Contributors
105109

106110
`Open Source Integrators <http://opensourceintegrators.com>`__
107111

108-
- Daniel Reis <dreis@opensourceintegrators.com>
109-
- Chandresh Thakkar <cthakkr@opensourceintegrators.com>
110-
- Urvisha Desai <udesai@opensourceintegrators.com>
112+
- Daniel Reis <dreis@opensourceintegrators.com>
113+
- Chandresh Thakkar <cthakkr@opensourceintegrators.com>
114+
- Urvisha Desai <udesai@opensourceintegrators.com>
111115

112116
`WeSolved <http://wesolved.com>`__
113117

114-
- Robin Conjour <rconjour@wesolved.com>
118+
- Robin Conjour <rconjour@wesolved.com>
115119

116120
`Dynapps <http://dynapps.eu>`__
117121

118-
- Bert Van Groenendael <bert.vangroenendael@dynapps.eu>
122+
- Bert Van Groenendael <bert.vangroenendael@dynapps.eu>
119123

120124
Maintainers
121125
-----------
@@ -130,6 +134,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
130134
mission is to support the collaborative development of Odoo features and
131135
promote its widespread use.
132136

133-
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/18.0/base_user_role_company>`_ project on GitHub.
137+
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/19.0/base_user_role_company>`_ project on GitHub.
134138

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

base_user_role_company/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "User roles by company",
6-
"version": "18.0.1.0.2",
6+
"version": "19.0.1.0.0",
77
"category": "Tools",
88
"author": "Open Source Integrators, Odoo Community Association (OCA)",
99
"license": "AGPL-3",

base_user_role_company/controllers/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
class HomeExtended(Home):
1010
@http.route()
11-
def web_load_menus(self, unique):
12-
response = super().web_load_menus(unique)
11+
def web_load_menus(self, *args, **kwargs):
12+
response = super().web_load_menus(*args, **kwargs)
1313
# On logout & re-login we could see wrong menus being rendered
1414
# To avoid this, menu http cache must be disabled
15-
response.headers.remove("Cache-Control")
15+
# Using .pop() as Werkzeug Headers no longer supports __delitem__ (del)
16+
response.headers.pop("Cache-Control", None)
1617
return response

base_user_role_company/models/ir_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class IrHttp(models.AbstractModel):
99
_inherit = "ir.http"
1010

11-
def session_info(self):
11+
def session_info(self, *args, **kwargs):
1212
"""
1313
Based on the selected companies (cids),
1414
calculate the roles to enable.
1515
A role should be enabled only when it applies to all selected companies.
1616
"""
17-
result = super().session_info()
17+
result = super().session_info(*args, **kwargs)
1818
if self.env.user.role_line_ids:
1919
cids_str = request.httprequest.cookies.get("cids", str(self.env.company.id))
2020
cids = [int(cid) for cid in cids_str.split("-")]

base_user_role_company/models/role.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def _check_company(self):
2828
raise ValidationError(
2929
self.env._(
3030
'User "%(user)s" does not have access to the company '
31-
'"%(company)s"'
31+
'"%(company)s"',
32+
user=record.user_id.name,
33+
company=record.company_id.name,
3234
)
33-
% {"user": record.user_id.name, "company": record.company_id.name}
3435
)
3536

36-
_sql_constraints = [
37-
(
38-
"user_role_uniq",
39-
"unique (user_id,role_id,company_id)",
40-
"Roles can be assigned to a user only once at a time",
41-
)
42-
]
37+
# Override parent unique constraint to allow the same role multiple times
38+
# for a user, provided company_id differs.
39+
_user_role_uniq = models.Constraint(
40+
"UNIQUE (user_id, role_id, company_id)",
41+
"Roles can be assigned to a user only once at a time",
42+
)

base_user_role_company/models/user.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
class ResUsers(models.Model):
88
_inherit = "res.users"
99

10-
@classmethod
11-
def authenticate(cls, db, credential, user_agent_env):
12-
auth_info = super().authenticate(db, credential, user_agent_env)
13-
# On login, ensure the proper roles are applied
14-
# The last Role applied may not be the correct one,
15-
# sonce the new session current company can be different
16-
with cls.pool.cursor() as cr:
17-
env = api.Environment(cr, auth_info["uid"], {})
10+
def authenticate(self, *args, **kwargs):
11+
auth_info = super().authenticate(*args, **kwargs)
12+
# Ensure proper roles are applied for the logged-in user
13+
uid = auth_info.get("uid") if isinstance(auth_info, dict) else None
14+
if uid:
15+
env = api.Environment(self.env.cr, uid, {})
1816
if env.user.role_line_ids:
1917
env.user.set_groups_from_roles()
2018
return auth_info
2119

22-
def _get_enabled_roles(self):
23-
res = super()._get_enabled_roles()
20+
def _get_enabled_roles(self, *args, **kwargs):
21+
res = super()._get_enabled_roles(*args, **kwargs)
2422
if self.role_line_ids:
2523
active_roles = self.env["res.users.role.line"]
2624
if self.env.context.get("active_company_ids"):
@@ -32,8 +30,9 @@ def _get_enabled_roles(self):
3230
active_roles |= role_line
3331
elif role_line.company_id.id in company_ids:
3432
role_line_companies = self.role_line_ids.filtered(
35-
lambda x, rl=role_line: x.role_id == rl.role_id
36-
and x.company_id.id in company_ids
33+
lambda x, rl=role_line: (
34+
x.role_id == rl.role_id and x.company_id.id in company_ids
35+
)
3736
)
3837
if len(role_line_companies) == len(company_ids):
3938
active_roles |= role_line

base_user_role_company/static/description/index.html

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>User roles by company</title>
6+
<title>README.rst</title>
77
<style type="text/css">
88

99
/*
@@ -360,16 +360,21 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document" id="user-roles-by-company">
364-
<h1 class="title">User roles by company</h1>
363+
<div class="document">
365364

365+
366+
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367+
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368+
</a>
369+
<div class="section" id="user-roles-by-company">
370+
<h1>User roles by company</h1>
366371
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367372
!! This file is generated by oca-gen-addon-readme !!
368373
!! changes will be overwritten. !!
369374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370375
!! source digest: sha256:22170e229c468ec41046141f10de50f397080458a7de6004f4a453721c02ca2f
371376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-backend/tree/18.0/base_user_role_company"><img alt="OCA/server-backend" src="https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-base_user_role_company"><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-backend&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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-backend/tree/19.0/base_user_role_company"><img alt="OCA/server-backend" src="https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-backend-19-0/server-backend-19-0-base_user_role_company"><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-backend&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373378
<p>Enable User Roles depending on the Companies selected.</p>
374379
<p>A company specific Role will only be enabled if it is set for <strong>all</strong>
375380
the currently selected companies.</p>
@@ -391,7 +396,7 @@ <h1 class="title">User roles by company</h1>
391396
</ul>
392397
</div>
393398
<div class="section" id="configuration">
394-
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
399+
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
395400
<p>Roles are set on the User form.</p>
396401
<p>The “Company” additional column allows to set a Role as only valid for
397402
specific companies.</p>
@@ -400,7 +405,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
400405
selection rules.</p>
401406
</div>
402407
<div class="section" id="usage">
403-
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
408+
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
404409
<p>Select the active companies from the web client widget, near the top
405410
right corner. When doing so, the User’s security Groups are recomputed,
406411
based on the Roles.</p>
@@ -415,34 +420,34 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
415420
</ul>
416421
</li>
417422
<li>When selecting active companies from the UI widget:<ul>
418-
<li>If only “My Company (San Francisco)” is active, “SALES PERSON” will
419-
be active.</li>
420-
<li>If only “My Company (Chicago)” is active, “SALES PERSON” and “SALES
421-
MANAGER” will be active.</li>
423+
<li>If only “My Company (San Francisco)” is active, “SALES PERSON”
424+
will be active.</li>
425+
<li>If only “My Company (Chicago)” is active, “SALES PERSON” and
426+
“SALES MANAGER” will be active.</li>
422427
<li>If both “My Company (San Francisco)” and “My Company (Chicago)” is
423428
active, “SALES PERSON” will be active.</li>
424429
</ul>
425430
</li>
426431
</ul>
427432
</div>
428433
<div class="section" id="bug-tracker">
429-
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
434+
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
430435
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-backend/issues">GitHub Issues</a>.
431436
In case of trouble, please check there if your issue has already been reported.
432437
If you spotted it first, help us to smash it by providing a detailed and welcomed
433-
<a class="reference external" href="https://github.com/OCA/server-backend/issues/new?body=module:%20base_user_role_company%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
438+
<a class="reference external" href="https://github.com/OCA/server-backend/issues/new?body=module:%20base_user_role_company%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
434439
<p>Do not contact contributors directly about support or help with technical issues.</p>
435440
</div>
436441
<div class="section" id="credits">
437-
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
442+
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
438443
<div class="section" id="authors">
439-
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
444+
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
440445
<ul class="simple">
441446
<li>Open Source Integrators</li>
442447
</ul>
443448
</div>
444449
<div class="section" id="contributors">
445-
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
450+
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
446451
<p><a class="reference external" href="http://opensourceintegrators.com">Open Source Integrators</a></p>
447452
<blockquote>
448453
<ul class="simple">
@@ -465,18 +470,19 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
465470
</blockquote>
466471
</div>
467472
<div class="section" id="maintainers">
468-
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
473+
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
469474
<p>This module is maintained by the OCA.</p>
470475
<a class="reference external image-reference" href="https://odoo-community.org">
471476
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
472477
</a>
473478
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
474479
mission is to support the collaborative development of Odoo features and
475480
promote its widespread use.</p>
476-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-backend/tree/18.0/base_user_role_company">OCA/server-backend</a> project on GitHub.</p>
481+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-backend/tree/19.0/base_user_role_company">OCA/server-backend</a> project on GitHub.</p>
477482
<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>
478483
</div>
479484
</div>
480485
</div>
486+
</div>
481487
</body>
482488
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import test_role_per_company
22
from . import test_use_only_enabled_roles
3+
from . import test_load_menus
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2026 Open Source Integrators
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
from odoo.tests.common import HttpCase
5+
6+
7+
class LoadMenusTests(HttpCase):
8+
def setUp(self):
9+
super().setUp()
10+
self.authenticate("admin", "admin")
11+
12+
def test_load_menus(self):
13+
"Expect no errors on HomeExtended.web_load_menus controller"
14+
self.url_open("/web/webclient/load_menus")

0 commit comments

Comments
 (0)