Skip to content

Commit

Permalink
[ENH] hr_operating_unit: add OU to department and fix domain users
Browse files Browse the repository at this point in the history
  • Loading branch information
ps-tubtim committed Jan 18, 2024
1 parent 955b206 commit 183732c
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 9 deletions.
3 changes: 2 additions & 1 deletion hr_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
1 change: 1 addition & 0 deletions hr_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions hr_operating_unit/models/hr_department.py
Original file line number Diff line number Diff line change
@@ -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()),
)
15 changes: 10 additions & 5 deletions hr_operating_unit/models/hr_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
1 change: 1 addition & 0 deletions hr_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Gonzalo González Domínguez <[email protected]>
* Murtaza Mithaiwala <[email protected]>
* Pimolnat Suntian <[email protected]>
2 changes: 1 addition & 1 deletion hr_operating_unit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion hr_operating_unit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add the operating unit to Employee
Add the operating unit to Employee/Department
14 changes: 14 additions & 0 deletions hr_operating_unit/security/security.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="ir_rule_hr_department_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="hr.model_hr_department" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
</field>
<field name="name">Department from allowed operating units</field>
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
<field name="global" eval="True" />
</record>

<record id="ir_rule_hr_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="hr.model_hr_employee" />
<field
Expand Down
46 changes: 46 additions & 0 deletions hr_operating_unit/views/hr_department_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_department_form" model="ir.ui.view">
<field name="model">hr.department</field>
<field name="inherit_id" ref="hr.view_department_form" />
<field name="arch" type="xml">
<field name="parent_id" position="after">
<field
name="operating_unit_id"
options="{'no_create': True}"
domain="[('company_id','=', company_id)]"
groups="operating_unit.group_multi_operating_unit"
/>
</field>
</field>
</record>
<record id="view_department_tree" model="ir.ui.view">
<field name="model">hr.department</field>
<field name="inherit_id" ref="hr.view_department_tree" />
<field name="arch" type="xml">
<field name="parent_id" position="after">
<field
name="operating_unit_id"
groups="operating_unit.group_multi_operating_unit"
optional="hide"
/>
</field>
</field>
</record>
<record id="view_department_filter" model="ir.ui.view">
<field name="model">hr.department</field>
<field name="inherit_id" ref="hr.view_department_filter" />
<field name="arch" type="xml">
<field name="manager_id" position="after">
<field name="operating_unit_id" />
</field>
<filter name="inactive" position="after">
<filter
string="Operating Unit"
name="operating_unit_id"
context="{'group_by': 'operating_unit_id'}"
/>
</filter>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<field name="company_id" position="after">
<field
name="operating_unit_ids"
domain="[('user_ids', 'in', uid)]"
groups="operating_unit.group_multi_operating_unit"
widget="many2many_tags"
options="{'no_create': True}"
Expand Down

0 comments on commit 183732c

Please sign in to comment.