From ce99855a831448488f0fd4f0e7c652aabe78a4ef Mon Sep 17 00:00:00 2001 From: ps-tubtim Date: Tue, 14 Feb 2023 11:22:13 +0700 Subject: [PATCH] [ENH] hr_operating_unit: add OU to department and fix domain users --- hr_operating_unit/README.rst | 11 +++-- hr_operating_unit/__manifest__.py | 3 +- hr_operating_unit/models/__init__.py | 1 + hr_operating_unit/models/hr_department.py | 13 ++++++ hr_operating_unit/models/hr_operating_unit.py | 15 ++++-- hr_operating_unit/readme/CONTRIBUTORS.rst | 1 + hr_operating_unit/readme/DESCRIPTION.rst | 2 +- hr_operating_unit/readme/USAGE.rst | 2 +- hr_operating_unit/security/security.xml | 14 ++++++ .../static/description/index.html | 9 ++-- .../views/hr_department_views.xml | 46 +++++++++++++++++++ ...{hr_employee.xml => hr_employee_views.xml} | 1 - 12 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 hr_operating_unit/models/hr_department.py create mode 100644 hr_operating_unit/views/hr_department_views.xml rename hr_operating_unit/views/{hr_employee.xml => hr_employee_views.xml} (97%) diff --git a/hr_operating_unit/README.rst b/hr_operating_unit/README.rst index b6d026bce8..6ff6889201 100644 --- a/hr_operating_unit/README.rst +++ b/hr_operating_unit/README.rst @@ -19,15 +19,15 @@ HR Operating Unit .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-hr_operating_unit :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/213/15.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/operating-unit&target_branch=15.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| This module introduces the following features: -* Adds the Operating Unit (OU) to the Employee. +* Adds the Operating Unit (OU) to the Employee/Department. * The Employees's default Operating Unit (OU) is proposed at the time of creation getting it from the logged user. @@ -40,7 +40,7 @@ This module introduces the following features: Usage ===== -Add the operating unit to Employee +Add the operating unit to Employee/Department Bug Tracker =========== @@ -65,6 +65,7 @@ Contributors * Gonzalo González Domínguez * Murtaza Mithaiwala +* Pimolnat Suntian Maintainers ~~~~~~~~~~~ diff --git a/hr_operating_unit/__manifest__.py b/hr_operating_unit/__manifest__.py index 6fb16022d5..b183d48310 100644 --- a/hr_operating_unit/__manifest__.py +++ b/hr_operating_unit/__manifest__.py @@ -10,7 +10,8 @@ "depends": ["hr", "operating_unit"], "data": [ "security/security.xml", - "views/hr_employee.xml", + "views/hr_department_views.xml", + "views/hr_employee_views.xml", ], "installable": True, } diff --git a/hr_operating_unit/models/__init__.py b/hr_operating_unit/models/__init__.py index 297b40f34f..c6074f5ad0 100644 --- a/hr_operating_unit/models/__init__.py +++ b/hr_operating_unit/models/__init__.py @@ -1,4 +1,5 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import hr_department from . import hr_employee_base from . import hr_operating_unit diff --git a/hr_operating_unit/models/hr_department.py b/hr_operating_unit/models/hr_department.py new file mode 100644 index 0000000000..f5b655463b --- /dev/null +++ b/hr_operating_unit/models/hr_department.py @@ -0,0 +1,13 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Department(models.Model): + _inherit = "hr.department" + + operating_unit_id = fields.Many2one( + comodel_name="operating.unit", + string="Operating Unit", + default=lambda self: (self.env["res.users"].operating_unit_default_get()), + ) diff --git a/hr_operating_unit/models/hr_operating_unit.py b/hr_operating_unit/models/hr_operating_unit.py index 985d792f07..3f0c6d1220 100644 --- a/hr_operating_unit/models/hr_operating_unit.py +++ b/hr_operating_unit/models/hr_operating_unit.py @@ -7,9 +7,14 @@ class OperatingUnit(models.Model): _inherit = "operating.unit" employee_ids = fields.Many2many( - "hr.employee", - "operating_unit_employees_rel", - "operating_unit_id", - "employee_id", - "Employees Allowed", + comodel_name="hr.employee", + relation="operating_unit_employees_rel", + column1="operating_unit_id", + column2="employee_id", + string="Employees Allowed", + ) + department_ids = fields.One2many( + comodel_name="hr.department", + inverse_name="operating_unit_id", + string="Departments", ) diff --git a/hr_operating_unit/readme/CONTRIBUTORS.rst b/hr_operating_unit/readme/CONTRIBUTORS.rst index 031666432a..ceddb7d9bf 100644 --- a/hr_operating_unit/readme/CONTRIBUTORS.rst +++ b/hr_operating_unit/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Gonzalo González Domínguez * Murtaza Mithaiwala +* Pimolnat Suntian diff --git a/hr_operating_unit/readme/DESCRIPTION.rst b/hr_operating_unit/readme/DESCRIPTION.rst index 31fc8900ba..6781bb45c0 100644 --- a/hr_operating_unit/readme/DESCRIPTION.rst +++ b/hr_operating_unit/readme/DESCRIPTION.rst @@ -1,6 +1,6 @@ This module introduces the following features: -* Adds the Operating Unit (OU) to the Employee. +* Adds the Operating Unit (OU) to the Employee/Department. * The Employees's default Operating Unit (OU) is proposed at the time of creation getting it from the logged user. diff --git a/hr_operating_unit/readme/USAGE.rst b/hr_operating_unit/readme/USAGE.rst index c22c0a5d4e..0899f084be 100644 --- a/hr_operating_unit/readme/USAGE.rst +++ b/hr_operating_unit/readme/USAGE.rst @@ -1 +1 @@ -Add the operating unit to Employee +Add the operating unit to Employee/Department diff --git a/hr_operating_unit/security/security.xml b/hr_operating_unit/security/security.xml index b8a39f2320..90a733581a 100644 --- a/hr_operating_unit/security/security.xml +++ b/hr_operating_unit/security/security.xml @@ -1,6 +1,20 @@ + + + ['|', + ('operating_unit_id', '=', False), + ('operating_unit_id', 'in', user.operating_unit_ids.ids)] + + Department from allowed operating units + + + + + + + - + HR Operating Unit