Repository navigation
[18.0][ADD] web_operating_unit_switcher: session based OU switcher - #891
luc-demeyer wants to merge 20 commits into
Conversation
|
@solomonprabu |
…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).
…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).
…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).
| context = self.env.context | ||
| if "current_operating_unit_id" in context: | ||
| ou_id = context["current_operating_unit_id"] | ||
| else: | ||
| ou_id = self.env.user.default_operating_unit_id.id |
There was a problem hiding this comment.
You can replace these lines with below code
ou_id = self.env.context.get("current_operating_unit_id", False) or self.env.user.default_operating_unit_id.id
| if "current_operating_unit_id" in self.env.context: | ||
| context_ou_id = self.env.context["current_operating_unit_id"] | ||
| if context_ou_id: | ||
| return self.env["operating.unit"].browse(context_ou_id) | ||
| return self.env["operating.unit"] |
There was a problem hiding this comment.
You can replace these lines with ,
context = self.env.context
if "current_operating_unit_id" in context:
return self.env["operating.unit"].browse(context.get("current_operating_unit_id", []))
There was a problem hiding this comment.
@LINTOANTONY007
thanks for your feedback, I have simplified your suggestion a bit further and pushed the following code change
context = self.env.context
if "current_operating_unit_id" in context:
return self.env["operating.unit"].browse(
context["current_operating_unit_id"]
)
in the js code I set "ouId || false" to the context key hence no context.get needed.
d47b1e9 to
b1e643d
Compare
|
@sbidoul |
|
@luc-demeyer that's not a false alert, we have no CLA for that person. @solomonprabu if you are available to click on the CLA button in #891 (comment), that would be helpful. The procedure is simple and only takes a few seconds. |
I have signed the CLA, sorry for keeping youwaiting :) |
|
It is a very interesting module and it works good. Not a blocking thing but I think web_operating_unit_switch would be a more conventional name. One commit per module is a requirement, web_easy_switch_operating_unit should have only one commit, because this is an [ADD]. |
…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).
|
@AaronHForgeFlow |
|
@luc-demeyer web_operating_unit_switcher sounds good. Thanks. |
b1e643d to
873afb1
Compare
|
@AaronHForgeFlow |
|
@luc-demeyer thanks, if propose a PR with the copier update I would merge it |
886c5f4 to
1c77cf1
Compare
|
This PR is ready for merge when
For the javascript unit tests I needed to update the CI config. There is also a long history behind this module: I propose we squash all commits from Solomon into a singe commit (we don't have the prior Odoo 8.0 and 13.0 history if his PR). But several operating_unit modules are also adapted for the injection of the active OU in the context key and the associated enhancements to the unit tests. |
|
I missed your demand "if propose a PR with the copier update I would merge it" while typing my question on how we'll squash the commits. |
|
@luc-demeyer Can you please check the copier update PR? #898 |
…removal of Controller as OWL adaptation makes it redundant
…xed pre-commit erros in .js file
…ion and added try-catch block
Refactor this module to allow a different OU per browser tab, following the same behavior as Odoo's standard company switcher.
In res.users,_get_default_operating_unit(), check current_operating_unit_id in context first so the cookie-based session OU takes priority over the user's DB default, enabling a different OU per browser tab. In ir.rule,_eval_context(), read the session OU from context directly (avoids a recursive access check on operating.unit). When a specific OU is active, narrow operating_unit_ids to that single OU so all security rules filter records to the selected OU — mirroring the company switcher behaviour.
Adapt the sale.order _compute_operating_unit_id(), _compute_team_id() and _check_team_operating_unit() so that only sales teams with an OU set propagate their OU. For shared (OU less) teams the session OU is used with fallback to the user's default operating unit.
Replace check_company=True on crm.team,operating_unit_id with an
explicit domain that includes OUs from all allowed companies.
With check_company=True, a team without a company_id generates domain
[('company_id', '=', False)], hiding all OUs (since an OU has always
a company).
Adapt res.partner,operating_unit_default_get() so that the session OU is used.
Override ir.rule,_compute_domain_keys() to include current_operating_unit_id in the domain cache key.
Distinguish between "current_operating_unit_id key absent" (switcher not active → fall back to user's default OU) and "key present but False" (user explicitly selected No OU → no fallback). In res.users,_get_default_operating_unit(), return an empty recordset when the key is present but False, instead of falling back to the user's default OU. In ir.rule,_eval_context(), read the key directly instead of using the "or" shortcut, so ou_id stays False when No OU is selected and effective_ou_ids falls back to all allowed OUs.
87bf3cd to
d30c07f
Compare
|
@AaronHForgeFlow Can you also let me know how to squash the commits (cf. my proposal and questions earlier in this thread) so that we are ready for merge ? |
this PR superceeds #853 in order to align the OU switcher behavior to Odoo's standard company switcher : session based OU switcher so that a different OU can selected by browser tab.