Skip to content

Commit

Permalink
[ADD] hr_employee_category_parent (OCA#366)
Browse files Browse the repository at this point in the history
* [ADD] hr_employee_category_parent

* [IMP] human readable name
  • Loading branch information
hbrunn authored and Iryna Vushnevska committed Mar 5, 2019
1 parent 2bb43d5 commit 11fb85b
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 0 deletions.
63 changes: 63 additions & 0 deletions hr_employee_category_parent/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===========================
HR Employee Category Parent
===========================

This module was written to restore the employee category hierarchy from v8 and before.

Usage
=====

To use this module, you need to:

#. go to some employee category and assign a parent

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/116/10.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/hr/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.

Roadmap
=======

* some hierarchy sensitive name search would be nice. Maybe better create `base_mixin_parent` in server-tools that handles hierarchical structures generally and use it here

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Holger Brunn <hbrunn@therp.nl>

Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

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.
4 changes: 4 additions & 0 deletions hr_employee_category_parent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
20 changes: 20 additions & 0 deletions hr_employee_category_parent/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "HR Employee Category Parent",
"version": "10.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Human Resources",
"summary": "Categorize your employee categories",
"depends": [
'hr',
],
"data": [
"views/hr_employee_category.xml",
],
"demo": [
"demo/hr_employee_category.xml",
],
}
16 changes: 16 additions & 0 deletions hr_employee_category_parent/demo/hr_employee_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="cat1" model="hr.employee.category">
<field name="name">Category 1</field>
</record>
<record id="cat2" model="hr.employee.category">
<field name="name">Category 2</field>
<field name="parent_id" ref="cat1" />
</record>
<record id="cat3" model="hr.employee.category">
<field name="name">Category 3</field>
<field name="parent_id" ref="cat2" />
</record>
</data>
</openerp>
4 changes: 4 additions & 0 deletions hr_employee_category_parent/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import hr_employee_category
40 changes: 40 additions & 0 deletions hr_employee_category_parent/models/hr_employee_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import _, api, exceptions, fields, models


class HrEmployeeCategory(models.Model):
_inherit = 'hr.employee.category'

parent_id = fields.Many2one('hr.employee.category', 'Parent category')

@api.multi
def name_get(self):
return [
(
this.id,
' / '.join(
p.name for p in reversed(list(this._iter_parents(True)))
),
)
for this in self
]

@api.multi
def _iter_parents(self, include_self=False):
self.ensure_one()
if not include_self:
self = self.parent_id
while self:
yield self
self = self.parent_id

@api.constrains('parent_id')
def _constrain_parent_id(self):
for this in self:
for parent in this._iter_parents():
if parent == this:
raise exceptions.ValidationError(
_('You can\'t create cyclic hierarchies'),
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions hr_employee_category_parent/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_hr_employee_category_parent
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import exceptions
from openerp.tests.common import TransactionCase


class TestHrCategoryParent(TransactionCase):
def test_hr_employee_category_parent(self):
with self.assertRaises(exceptions.ValidationError):
with self.env.cr.savepoint():
self.env.ref('hr_employee_category_parent.cat3').write({
'parent_id':
self.env.ref('hr_employee_category_parent.cat3').id,
})
with self.assertRaises(exceptions.ValidationError):
with self.env.cr.savepoint():
self.env.ref('hr_employee_category_parent.cat1').write({
'parent_id':
self.env.ref('hr_employee_category_parent.cat3').id,
})
self.assertEqual(
self.env.ref('hr_employee_category_parent.cat3').display_name,
'Category 1 / Category 2 / Category 3',
)
24 changes: 24 additions & 0 deletions hr_employee_category_parent/views/hr_employee_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_hr_employee_category_form" model="ir.ui.view">
<field name="model">hr.employee.category</field>
<field name="inherit_id" ref="hr.view_employee_category_form" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="parent_id" />
</field>
</field>
</record>
<record id="view_hr_employee_category_tree" model="ir.ui.view">
<field name="model">hr.employee.category</field>
<field name="inherit_id" ref="hr.view_employee_category_list" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="parent_id" />
<field name="display_name" />
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 11fb85b

Please sign in to comment.