Skip to content

Commit

Permalink
[ADD] operating_unit_selector_widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidderen-noviat authored and jdidderen committed Oct 1, 2024
1 parent 88355e7 commit ac20953
Show file tree
Hide file tree
Showing 24 changed files with 1,113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contract_operating_unit/security/contract_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model_id" ref="contract.model_contract_contract" />
<field
name="domain_force"
>['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field>
>['|',('operating_unit_id','=',False),('operating_unit_id','in',operating_unit_ids)]</field>
<field name="name">Contracts from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
Expand Down
8 changes: 8 additions & 0 deletions operating_unit/models/ir_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).


import logging

from odoo import api, models

_logger = logging.getLogger(__name__)


class IrRule(models.Model):
_inherit = "ir.rule"
Expand All @@ -17,4 +21,8 @@ def _eval_context(self):
"operating_unit_id": self.env.user.default_operating_unit_id.id,
}
)
_logger.warning("eval_context")
_logger.warning(res)
_logger.warning(self.env.user.operating_units())
_logger.warning(self.env.user.operating_units().ids)
return res
2 changes: 2 additions & 0 deletions operating_unit/models/operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class OperatingUnit(models.Model):
_name = "operating.unit"
_order = "sequence, name"
_description = "Operating Unit"
_rec_names_search = ["name", "code"]

Expand All @@ -27,6 +28,7 @@ class OperatingUnit(models.Model):
"user_id",
"Users Allowed",
)
sequence = fields.Integer(default=10)

_sql_constraints = [
(
Expand Down
1 change: 1 addition & 0 deletions operating_unit/view/operating_unit_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<field name="model">operating.unit</field>
<field name="arch" type="xml">
<tree>
<field name="sequence" widget="handle" />
<field name="code" />
<field name="name" />
<field name="company_id" groups="base.group_multi_company" />
Expand Down
92 changes: 92 additions & 0 deletions operating_unit_selector_widget/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
================================
Operating Unit - Selector Widget
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a52b68f6bd7b57c3b6ee835e0bee09129e747eafb86e420a384d3b12a65d4837
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/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
:target: https://github.com/OCA/operating-unit/tree/17.0/operating_unit_selector_widget
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-17-0/operating-unit-17-0-operating_unit_selector_widget
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Add a new widget to choose the wanted operating units and only view
datas related to these operating units

|image|

.. |image| image:: https://raw.githubusercontent.com/OCA/operating-unit/17.0/operating_unit_selector_widget/static/description/widget.png

**Table of contents**

.. contents::
:local:

Usage
=====

Install the module and be sure to have an user with several operating
units.

Known issues / Roadmap
======================



Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/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
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20operating_unit_selector_widget%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Jérémy Didderen

Contributors
------------

- Jérémy Didderen

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/17.0/operating_unit_selector_widget>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions operating_unit_selector_widget/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions operating_unit_selector_widget/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024-TODAY Jérémy Didderen
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Operating Unit - Selector Widget",
"summary": "Widget dedicated to choose the active operating units.",
"version": "17.0.1.0.0",
"author": "Jérémy Didderen, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Generic",
"depends": [
"operating_unit",
],
"license": "LGPL-3",
"assets": {
"web.assets_backend": [
"operating_unit_selector_widget/static/src/operating_unit_service.esm.js",
"operating_unit_selector_widget/static/src/switch_operating_unit_menu/switch_operating_unit_menu.xml",
"operating_unit_selector_widget/static/src/switch_operating_unit_menu/switch_operating_unit_menu.esm.js",
],
"web.qunit_suite_tests": ["operating_unit_selector_widget/static/tests/*.js"],
},
}
2 changes: 2 additions & 0 deletions operating_unit_selector_widget/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_http
from . import res_users
29 changes: 29 additions & 0 deletions operating_unit_selector_widget/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024-TODAY Jérémy Didderen
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models


class Http(models.AbstractModel):
_inherit = "ir.http"

def session_info(self):
session_info = super().session_info()
user = self.env.user
is_internal_user = user.has_group("base.group_user")
if is_internal_user:
session_info.update(
{
"user_ous": {
"current_ou": user.default_operating_unit_id.id,
"allowed_ous": {
ou.id: {
"id": ou.id,
"name": ou.name,
"sequence": ou.sequence,
}
for ou in user.operating_unit_ids
},
},
}
)
return session_info
22 changes: 22 additions & 0 deletions operating_unit_selector_widget/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024-TODAY Jérémy Didderen
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import logging

from odoo import _, models
from odoo.exceptions import AccessError

_logger = logging.getLogger(__name__)


class ResUsers(models.Model):
_inherit = "res.users"

def operating_units(self):
operating_unit_ids = self.env.context.get("allowed_ou_ids", [])
user_ou_ids = self.operating_unit_ids.ids
if operating_unit_ids:
if not self.env.su:
if set(operating_unit_ids) - set(user_ou_ids):
raise AccessError(_("Access to unauthorized or invalid companies."))
return self.env["operating.unit"].browse(operating_unit_ids)
return self.env["operating.unit"].browse(user_ou_ids)
3 changes: 3 additions & 0 deletions operating_unit_selector_widget/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions operating_unit_selector_widget/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Jérémy Didderen
3 changes: 3 additions & 0 deletions operating_unit_selector_widget/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add a new widget to choose the wanted operating units and only view datas related to these operating units

![image](../static/description/widget.png)
1 change: 1 addition & 0 deletions operating_unit_selector_widget/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions operating_unit_selector_widget/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Install the module and be sure to have an user with several operating units.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ac20953

Please sign in to comment.