From 399106c7212b3c7f10c49daaf2dadbc107376191 Mon Sep 17 00:00:00 2001 From: Bhavesh Heliconia Date: Tue, 24 Mar 2026 16:04:26 +0530 Subject: [PATCH] [IMP] operating_unit: Linked users button and bulk sync action --- operating_unit/README.rst | 31 ++++++++--- operating_unit/models/operating_unit.py | 57 ++++++++++++++++++++ operating_unit/readme/CONTRIBUTORS.md | 2 + operating_unit/readme/DESCRIPTION.md | 7 ++- operating_unit/readme/USAGE.md | 5 ++ operating_unit/static/description/index.html | 48 +++++++++-------- operating_unit/tests/test_operating_unit.py | 9 ++++ operating_unit/view/operating_unit_view.xml | 28 +++++++--- 8 files changed, 150 insertions(+), 37 deletions(-) diff --git a/operating_unit/README.rst b/operating_unit/README.rst index c8835be162..836a7b746b 100644 --- a/operating_unit/README.rst +++ b/operating_unit/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ============== Operating Unit ============== @@ -17,7 +13,7 @@ Operating Unit .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github @@ -32,14 +28,24 @@ Operating Unit |badge1| |badge2| |badge3| |badge4| |badge5| -An operating unit (OU) is an organizational entity part of a company, -with separate management ownership. Management by OU is aimed to -introduce the following features: +AnThis module maintains the administrative units (Operating Units) to +which resources can be associated. An Operating Unit (OU) is a child of +a Company. + +**Improvements in this version:** + +- Added a Stat Button on Operating Units to easily view and manage + linked users. with separate management ownership. Management by OU is + aimed to introduce the following features: - Data partitioning from other OU. + - Own sequencing schemes. + - User access administration for data processing and reporting. + - Product and customer independence of OU. + - OU specific P&L and Balance sheet. **Table of contents** @@ -62,6 +68,12 @@ Usage 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** + +On the Operating Unit form, a Stat Button "Users" is available to +quickly access all users linked to that unit, including managers of the +unit. + Known issues / Roadmap ====================== @@ -95,6 +107,9 @@ Contributors - Andrea Stirpe - Ooops, Ashish Hirpara - Daniel Lagin +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia Maintainers ----------- diff --git a/operating_unit/models/operating_unit.py b/operating_unit/models/operating_unit.py index ca29bd7906..7b66d20591 100644 --- a/operating_unit/models/operating_unit.py +++ b/operating_unit/models/operating_unit.py @@ -56,3 +56,60 @@ def create(self, vals_list): def write(self, vals): self.env.registry.clear_cache() return super().write(vals) + + def button_open_linked_users(self): + self.ensure_one() + action = self.env.ref( + "base.action_res_users", + raise_if_not_found=False, + ) + if not action: + return False + action_vals = action.read()[0] + + user_ids = set(self.user_ids.ids) + group = self.env.ref( + "operating_unit.group_manager_operating_unit", + raise_if_not_found=False, + ) + if group: + user_ids.update(group.users.ids) + + user_ids = list(user_ids) + + context = action_vals.get("context", {}) + if isinstance(context, str): + from odoo.tools.safe_eval import safe_eval + + context = safe_eval(context) + + context.update( + { + "create": False, + "edit": False, + "delete": False, + } + ) + action_vals["context"] = context + + if not user_ids: + return action_vals + + action_vals["domain"] = [("id", "in", user_ids)] + if len(user_ids) == 1: + form_view = self.env.ref("base.view_users_form") + action_vals.update( + { + "views": [(form_view.id, "form")], + "view_mode": "form", + "res_id": user_ids[0], + } + ) + else: + action_vals.update( + { + "views": [(False, "list"), (False, "form")], + "view_mode": "list,form", + } + ) + return action_vals diff --git a/operating_unit/readme/CONTRIBUTORS.md b/operating_unit/readme/CONTRIBUTORS.md index 9dfa45d524..17227d3544 100644 --- a/operating_unit/readme/CONTRIBUTORS.md +++ b/operating_unit/readme/CONTRIBUTORS.md @@ -4,3 +4,5 @@ - Andrea Stirpe \<\> - Ooops, Ashish Hirpara \<\> - Daniel Lagin \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/operating_unit/readme/DESCRIPTION.md b/operating_unit/readme/DESCRIPTION.md index 52bdc835cd..6ef5dc020e 100644 --- a/operating_unit/readme/DESCRIPTION.md +++ b/operating_unit/readme/DESCRIPTION.md @@ -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 +resources can be associated. An Operating Unit (OU) is a child of a +Company. + +**Improvements in this version:** +- Added a Stat Button on Operating Units to easily view and manage linked users. with separate management ownership. Management by OU is aimed to introduce the following features: diff --git a/operating_unit/readme/USAGE.md b/operating_unit/readme/USAGE.md index ba8abdaccf..6a78df16ba 100644 --- a/operating_unit/readme/USAGE.md +++ b/operating_unit/readme/USAGE.md @@ -1,2 +1,7 @@ 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** + +On the Operating Unit form, a Stat Button "Users" is available to quickly access all users linked to that unit, including managers of the unit. + diff --git a/operating_unit/static/description/index.html b/operating_unit/static/description/index.html index 33bbb08e03..0a6e794743 100644 --- a/operating_unit/static/description/index.html +++ b/operating_unit/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Operating Unit -
+
+

Operating Unit

- - -Odoo Community Association - -
-

Operating Unit

-

Beta License: LGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runboat

-

An operating unit (OU) is an organizational entity part of a company, -with separate management ownership. Management by OU is aimed to -introduce the following features:

+

Beta License: LGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runboat

+

AnThis module maintains the administrative units (Operating Units) to +which resources can be associated. An Operating Unit (OU) is a child of +a Company.

+

Improvements in this version:

    +
  • Added a Stat Button on Operating Units to easily view and manage +linked users. with separate management ownership. Management by OU is +aimed to introduce the following features:
  • Data partitioning from other OU.
  • Own sequencing schemes.
  • User access administration for data processing and reporting.
  • @@ -401,7 +400,7 @@

    Operating Unit

-

Configuration

+

Configuration

To configure this module, you need to:

  • Assign Multi Operating Unit group to user.
  • @@ -410,15 +409,19 @@

    Configuration

-

Usage

+

Usage

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

+

On the Operating Unit form, a Stat Button “Users” is available to +quickly access all users linked to that unit, including managers of the +unit.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -426,16 +429,16 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • ForgeFlow
  • Serpent Consulting Services Pvt. Ltd.
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -459,6 +466,5 @@

Maintainers

-
diff --git a/operating_unit/tests/test_operating_unit.py b/operating_unit/tests/test_operating_unit.py index a7f7ad95d1..24b9793e18 100644 --- a/operating_unit/tests/test_operating_unit.py +++ b/operating_unit/tests/test_operating_unit.py @@ -140,3 +140,12 @@ def test_create_multi_operating_unit(self): self.assertEqual(res[0].user_ids, self.user1) self.assertEqual(res[1].user_ids, self.user1) self.assertEqual(res[2].user_ids, self.user1) + + def test_button_open_linked_users(self): + """Test the Stat Button that opens linked users.""" + # Add another user to ou1 + self._create_user("user_extra", self.grp_ou_multi, self.company, [self.ou1]) + action = self.ou1.button_open_linked_users() + self.assertEqual(action["res_model"], "res.users") + self.assertEqual(action.get("view_mode"), "list,form") + self.assertIn("domain", action) diff --git a/operating_unit/view/operating_unit_view.xml b/operating_unit/view/operating_unit_view.xml index bda031e5e0..f5c462ab68 100644 --- a/operating_unit/view/operating_unit_view.xml +++ b/operating_unit/view/operating_unit_view.xml @@ -5,13 +5,27 @@ operating.unit
- - - - - - - + +
+ +
+ + + + + + + +