Skip to content

[18.0][IMP] operating_unit: Add linked users stat button and bulk unit synchronization - #834

Open
BhaveshHeliconia wants to merge 1 commit into
OCA:18.0from
HeliconiaIO:18.0-imp-operating_unit
Open

BhaveshHeliconia wants to merge 1 commit into
OCA:18.0from
HeliconiaIO:18.0-imp-operating_unit

Conversation

@BhaveshHeliconia

Copy link
Copy Markdown
Contributor

This pull request introduces two key improvements to the operating_unit module to enhance user management and visibility.

Key Improvements:

  • Users Stat Button on Operating Units: Provides quick access to all users linked to an OU (including managers) via a Stat Button on the form view.
  • Bulk Operating Unit Synchronization: A new server action on the Users list view to automatically assign OUs based on the user's allowed companies.

@AaronHForgeFlow

Copy link
Copy Markdown
Contributor

the stat button could be something useful, the server action I think it is not a generic enough feature to be included in the core module.

@BhaveshHeliconia
BhaveshHeliconia force-pushed the 18.0-imp-operating_unit branch from 342e60e to 2b43e2a Compare April 9, 2026 05:11
@BhaveshHeliconia

Copy link
Copy Markdown
Contributor Author

@AaronHForgeFlow, thanks for the feedback. I've removed the bulk synchronization feature and kept only the Stat Button. Documentation and tests have been updated accordingly.

Comment thread operating_unit/models/operating_unit.py Outdated
self.env.registry.clear_cache()
return super().write(vals)

def button_open_linked_users(self) -> dict:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain why you need all this code for an action? why don't simply create the action in xml and do smth like this (haven't tested the code, just an idea):

def button_open_linked_users(self):
action = self.env.ref("operating_unit.action_res_users_operating_unit").read()[0]
if len(self.user_ids) == 1:
action.update({
"view_mode": "form",
"res_id": self.user_ids.id,
})
else:
action["domain"] = [("id", "in", self.user_ids.ids)]
return action

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.

Thanks for the suggestion. I've improved the method accordingly.

@BhaveshHeliconia

Copy link
Copy Markdown
Contributor Author

ping @AaronHForgeFlow

Comment thread operating_unit/models/operating_unit.py Outdated
Comment on lines +62 to +68
action = self.env.ref(
"base.action_res_users",
raise_if_not_found=False,
)
if not action:
return False
action_vals = action.read()[0]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The usual pattern to get an action as dict is:

Suggested change
action = self.env.ref(
"base.action_res_users",
raise_if_not_found=False,
)
if not action:
return False
action_vals = action.read()[0]
action = self.env['ir.actions.actions']._for_xml_id("base.action_res_users")
# update `action`...
return action

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.

Thanks @sebalix! Updated

Comment thread operating_unit/readme/DESCRIPTION.md Outdated
@@ -1,4 +1,9 @@
An operating unit (OU) is an organizational entity part of a company,
AnThis module maintains the administrative units (Operating Units) to which

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
AnThis module maintains the administrative units (Operating Units) to which
This module maintains the administrative units (Operating Units) to which

Still, do we need to update the description here?

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.

Agreed. Reverted to keep the original description clean.

Comment thread operating_unit/readme/DESCRIPTION.md Outdated
Comment on lines +5 to +6
**Improvements in this version:**
- Added a Stat Button on Operating Units to easily view and manage linked users.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure we should include such changelog in the DESCRIPTION.md file.

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.

Reverted it back to its original state.

Comment thread operating_unit/readme/USAGE.md Outdated
This module defines the operating unit entity and the user's security
rules. Other modules extend the standard Odoo apps with the OU.

**Stat Button for Linked Users**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IMO there is no need to document such basic feature (it's a common UX helper in Odoo) in USAGE.md.

Is all of this generated by AI? :) If so, it deserves an Assisted-by: entry in the commit, see https://github.com/OCA/.github/blob/master/AI_POLICY.md .

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.

I have reverted USAGE.md back to its original state.

@BhaveshHeliconia

Copy link
Copy Markdown
Contributor Author

@sebalix Thanks for the review! I've addressed all your suggestions and reworked in this improvements PR.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants