Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg | ||
:target: https://www.gnu.org/licenses/lgpl.html | ||
:alt: License: LGPL-3 | ||
|
||
================================ | ||
HR Contract with Operating Units | ||
================================ | ||
|
||
This module introduces the following features: | ||
|
||
* Adds the Operating Unit (OU) to the Employee Contract. | ||
|
||
* Security rules are defined to ensure that users can only see the Contracts of that Operating Units in which they are allowed access to. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/213/9.0 | ||
|
||
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 smashing it by providing a detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Eficent Business and IT Consulting Services S.L. <contact@eficent.com> | ||
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. - | ||
# Jordi Ballester Alomar | ||
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import models | ||
from . import tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. - | ||
# Jordi Ballester Alomar | ||
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
{ | ||
"name": "HR Contract Operating Unit", | ||
"version": "9.0.1.0.0", | ||
"license": "LGPL-3", | ||
"author": "Eficent Business and IT Consulting Services S.L., " | ||
"Serpent Consulting Services Pvt. Ltd.," | ||
"Odoo Community Association (OCA)", | ||
"website": "http://www.eficent.com", | ||
"category": "Generic Modules/Human Resources", | ||
"depends": ["hr_contract", "operating_unit"], | ||
"data": [ | ||
"views/hr_contract_view.xml", | ||
"security/hr_contract_security.xml" | ||
], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. - | ||
# Jordi Ballester Alomar | ||
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import hr_contract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. - | ||
# Jordi Ballester Alomar | ||
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from openerp import fields, models | ||
|
||
|
||
class HrContract(models.Model): | ||
|
||
_inherit = 'hr.contract' | ||
|
||
operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', | ||
default=lambda self: | ||
self.env['res.users']. | ||
operating_unit_default_get(self._uid)) |
21 changes: 21 additions & 0 deletions
21
hr_contract_operating_unit/security/hr_contract_security.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2015 Eficent Business and IT Consulting Services S.L. | ||
Serpent Consulting Services Pvt. Ltd. | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) --> | ||
<odoo> | ||
<data noupdate="0"> | ||
|
||
<record id="ir_rule_hr_contract_allowed_operating_units" | ||
model="ir.rule"> | ||
<field name="model_id" ref="hr_contract.model_hr_contract"/> | ||
<field name="domain_force">['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field> | ||
<field name="name">Contracts from allowed operating units</field> | ||
<field name="global" eval="True"/> | ||
<field eval="0" name="perm_unlink"/> | ||
<field eval="0" name="perm_write"/> | ||
<field eval="1" name="perm_read"/> | ||
<field eval="0" name="perm_create"/> | ||
</record> | ||
|
||
</data> | ||
</odoo> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. - | ||
# Jordi Ballester Alomar | ||
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import test_hr_contract_operating_unit |
82 changes: 82 additions & 0 deletions
82
hr_contract_operating_unit/tests/test_hr_contract_operating_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. - | ||
# Jordi Ballester Alomar | ||
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from openerp.tests import common | ||
|
||
|
||
class TestHrContractOperatingUnit(common.TransactionCase): | ||
|
||
def setUp(self): | ||
super(TestHrContractOperatingUnit, self).setUp() | ||
|
||
self.res_users_model = self.env['res.users'] | ||
self.hr_contract_model = self.env['hr.contract'] | ||
self.hr_employee_model = self.env['hr.employee'] | ||
|
||
self.company = self.env.ref('base.main_company') | ||
self.contract_type = self.env.ref('hr_contract.hr_contract_type_emp') | ||
self.grp_hr_manager = self.env.ref('base.group_hr_manager') | ||
|
||
# Main Operating Unit | ||
self.ou1 = self.env.ref('operating_unit.main_operating_unit') | ||
# B2C Operating Unit | ||
self.b2c = self.env.ref('operating_unit.b2c_operating_unit') | ||
|
||
# Create Users | ||
self.user1 = self._create_user('User_1', self.grp_hr_manager, | ||
self.company, [self.ou1, self.b2c]) | ||
self.user2 = self._create_user('User_2', self.grp_hr_manager, | ||
self.company, [self.b2c]) | ||
|
||
# Create Employee | ||
self.emp = self._create_hr_employee() | ||
|
||
# Create Contracts | ||
self.hr_contract1 = self._create_hr_contract(self.user1, self.ou1) | ||
self.hr_contract2 = self._create_hr_contract(self.user2, self.b2c) | ||
|
||
def _create_user(self, login, groups, company, operating_units, | ||
context=None): | ||
"""Creates a user.""" | ||
group_ids = [group.id for group in groups] | ||
user = self.res_users_model.create({ | ||
'name': 'Test HR Contract User', | ||
'login': login, | ||
'password': 'demo', | ||
'email': 'example@yourcompany.com', | ||
'company_id': company.id, | ||
'company_ids': [(4, company.id)], | ||
'operating_unit_ids': [(4, ou.id) for ou in operating_units], | ||
'groups_id': [(6, 0, group_ids)] | ||
}) | ||
return user | ||
|
||
def _create_hr_employee(self): | ||
"""Creates an employee.""" | ||
emp = self.hr_employee_model.create({ | ||
'name': "Test Employee", | ||
}) | ||
return emp | ||
|
||
def _create_hr_contract(self, uid, operating_unit): | ||
"""Creates a contract for an employee.""" | ||
contract = self.hr_contract_model.sudo(uid).create({ | ||
'name': "Sample Contract", | ||
'operating_unit_id': operating_unit.id, | ||
'employee_id': self.emp.id, | ||
'type_id': self.contract_type.id, | ||
'wage': '10000', | ||
}) | ||
return contract | ||
|
||
def test_hr_contract_ou(self): | ||
"""Test Hr Contract Operating Unit""" | ||
# User 2 is only assigned to Operating Unit B2C, and cannot | ||
# Access Hr Contract records of Main Operating Unit. | ||
record = self.hr_contract_model.sudo(self.user2.id).search( | ||
[('id', '=', self.hr_contract1.id), | ||
('operating_unit_id', '=', self.ou1.id)]) | ||
self.assertEqual(record.ids, [], 'User 2 should not have access to ' | ||
'OU %s' % self.ou1.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2015 Eficent Business and IT Consulting Services S.L. | ||
Serpent Consulting Services Pvt. Ltd. | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) --> | ||
<openerp> | ||
<data> | ||
|
||
<record id="hr_contract_view_search" model="ir.ui.view"> | ||
<field name="name">hr.contract.view.search</field> | ||
<field name="model">hr.contract</field> | ||
<field name="inherit_id" ref="hr_contract.hr_contract_view_search"/> | ||
<field name="arch" type="xml"> | ||
<field name="employee_id" position="after"> | ||
<field name="operating_unit_id" groups="operating_unit.group_multi_operating_unit"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="hr_contract_view_form" model="ir.ui.view"> | ||
<field name="name">hr.contract.view.form</field> | ||
<field name="model">hr.contract</field> | ||
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="job_id" position="after"> | ||
<field name="operating_unit_id" groups="operating_unit.group_multi_operating_unit" options="{'no_create': True}"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="hr_contract_view_tree" model="ir.ui.view"> | ||
<field name="name">hr.contract.view.tree</field> | ||
<field name="model">hr.contract</field> | ||
<field name="inherit_id" ref="hr_contract.hr_contract_view_tree"/> | ||
<field name="arch" type="xml"> | ||
<field name="employee_id" position="after"> | ||
<field name="operating_unit_id" groups="operating_unit.group_multi_operating_unit"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</data> | ||
</openerp> |