Skip to content

[18.0][ADD] operating_unit_window_action_isolation - #888

Open
luc-demeyer wants to merge 5 commits into
OCA:18.0from
luc-demeyer:18.0-add-operating_unit_window_action_isolation
Open

luc-demeyer wants to merge 5 commits into
OCA:18.0from
luc-demeyer:18.0-add-operating_unit_window_action_isolation

Conversation

@luc-demeyer

Copy link
Copy Markdown
Contributor

This PR is based upon #858 but with two changes

  1. remove sale_operating_unit dependency
    This depends was added for unit tests based upon the sale.order window action.
    I moved the unit tests to a seperate module so that the depends becomes clean

  2. bug fix (cf. commit ed51858)

With this the module works correctly for 'single operating unit' users.
But in reality this module is intended for 'multi operating unit' users and requires the prerequisite 'web_easy_switch_operating_unit" module, cf. #853.

PR 853 got closed since it has been marked as stale and closed automatically afterwards.

I'll pick this work test it and make a new PR for this module.
After merging this one, we should imho add the web_easy_switch_operating_unit to the dependencies of the operating_unit_window_action_isolation.

FYI:
These modules are coming from https://github.com/sj3/canna-third-party.

ManfredNelvin and others added 4 commits June 4, 2026 13:12
The commit removes the dependency on 'sale_operating_unit', which was only required
for the unit tests.

The unit tests have been moved to a new module, operating_unit_window_action_isolation_sale.
Replace is_superuser() with uid == SUPERUSER_ID so that sudo() calls
do not bypass the operating unit domain filter.

The standard Odoo web client loads menu actions via _get_action_dict()
(cf. ir_actions.py) which calls self.sudo().read(), causing is_superuser()
to return True for every regular user and effectively disabling the filter
for all users.
@OCA-git-bot OCA-git-bot added series:18.0 mod:operating_unit_window_action_isolation Module operating_unit_window_action_isolation mod:operating_unit_window_action_isolation_sale Module operating_unit_window_action_isolation_sale labels Nov 5, 2026
"""Restrict actions to the user's default operating unit."""
result = super().read(fields=fields, load=load)

if self.env.uid == SUPERUSER_ID:

@LINTOANTONY007 LINTOANTONY007 Nov 6, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use self.env.is_superuser() ?

self.env.is_superuser() and self.env.uid == SUPERUSER_ID is same right ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LINTOANTONY007
it's completely different, cf. https://github.com/odoo/odoo/blob/df75d96296953382f277d6bdbe5fc703c7c717a1/odoo/api.py#L672

Have also a look to my commit message ed51858. This explains why the is_superuser() broke the functionality offered by the originating Odoo 13.0 module.

In Odoo 13.0 we also have
self.env.uid != SUPERUSER_ID
cf. https://github.com/sj3/canna-third-party/blob/e7b7bbf84c90d80f400b7a5b68fd081d95b78bef/operating_unit_window_action_isolation/models/ir_actions_act_window.py#L18

It's not clear to me why https://github.com/sj-onestein-nl has added this line in the code when creating the original module. I assume it was required to prevent a failing pipeline. Imho we can leave this SUPERUSER_ID exclusion in the code for the time being.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right. As noted in the commit, is_superuser() checks whether the environment is in superuser mode, not if the user itself is a superuser.

@LINTOANTONY007 LINTOANTONY007 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ByteMeAsap ByteMeAsap left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@luc-demeyer
luc-demeyer force-pushed the 18.0-add-operating_unit_window_action_isolation branch 2 times, most recently from 24bbf2d to d8a8777 Compare November 11, 2026 18:51
@luc-demeyer

Copy link
Copy Markdown
Contributor Author

@LINTOANTONY007 @ByteMeAsap
Thanks for reviewing this work.
I have added in the meanwhile one more commit to make this module also ready for the upcoming 'session/cookie based OU switcher' (cf. #891).

…omain

Replace direct access to user.default_operating_unit_id with
res.users,_get_default_operating_unit() so that the upcoming cookie-based
session OU takes priority (cf. OCA#891).
@luc-demeyer
luc-demeyer force-pushed the 18.0-add-operating_unit_window_action_isolation branch from d8a8777 to 5052ee0 Compare November 12, 2026 15:28
@luc-demeyer

Copy link
Copy Markdown
Contributor Author

@LINTOANTONY007
I have made here a similar simplification of the code as you suggested for #891

cf. ir_actions_act_window.py:

  19          context = self.env.context                                                                                                                                 
  20          if "current_operating_unit_id" in context:                                                                                                                 
  21 -            ou_id = context["current_operating_unit_id"]                                                                                                           
  22 -            user_ou = (                                                                                                                                            
  23 -                self.env["operating.unit"].browse(ou_id)                                                                                                           
  24 -                if ou_id                                                                                                                                         
  25 -                else self.env["operating.unit"]                                                                                                                    
  21 +            user_ou = self.env["operating.unit"].browse(                                                                                                           
  22 +                context["current_operating_unit_id"]                                                                                                               
  23              )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved mod:operating_unit_window_action_isolation_sale Module operating_unit_window_action_isolation_sale mod:operating_unit_window_action_isolation Module operating_unit_window_action_isolation ready to merge series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants