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.department + + + + + + + + + hr.department + + + + + + + + + hr.department + + + + + + + + + + + diff --git a/hr_operating_unit/views/hr_employee.xml b/hr_operating_unit/views/hr_employee_views.xml similarity index 97% rename from hr_operating_unit/views/hr_employee.xml rename to hr_operating_unit/views/hr_employee_views.xml index d0f54d0069..0de0306e82 100644 --- a/hr_operating_unit/views/hr_employee.xml +++ b/hr_operating_unit/views/hr_employee_views.xml @@ -30,7 +30,6 @@