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 authored and Saran440 committed Mar 8, 2023
1 parent 7d49119 commit cbf8048
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 18 deletions.
11 changes: 6 additions & 5 deletions hr_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
===========
Expand All @@ -65,6 +65,7 @@ Contributors

* Gonzalo González Domínguez <[email protected]>
* Murtaza Mithaiwala <[email protected]>
* Pimolnat Suntian <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
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
9 changes: 5 additions & 4 deletions hr_operating_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>HR Operating Unit</title>
<style type="text/css">

Expand Down Expand Up @@ -367,10 +367,10 @@ <h1 class="title">HR Operating Unit</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/hr_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-hr_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/213/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/operating-unit/tree/15.0/hr_operating_unit"><img alt="OCA/operating-unit" src="https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/operating-unit-15-0/operating-unit-15-0-hr_operating_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/operating-unit&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module introduces the following features:</p>
<ul class="simple">
<li>Adds the Operating Unit (OU) to the Employee.</li>
<li>Adds the Operating Unit (OU) to the Employee/Department.</li>
<li>The Employees’s default Operating Unit (OU) is proposed at the time of creation
getting it from the logged user.</li>
</ul>
Expand All @@ -389,7 +389,7 @@ <h1 class="title">HR Operating Unit</h1>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>Add the operating unit to Employee</p>
<p>Add the operating unit to Employee/Department</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
Expand All @@ -412,6 +412,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Gonzalo González Domínguez &lt;<a class="reference external" href="mailto:meigallo&#64;meigallodixital.com">meigallo&#64;meigallodixital.com</a>&gt;</li>
<li>Murtaza Mithaiwala &lt;<a class="reference external" href="mailto:mmithaiwala&#64;opensourceintegrators.com">mmithaiwala&#64;opensourceintegrators.com</a>&gt;</li>
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
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 cbf8048

Please sign in to comment.