Skip to content

Commit

Permalink
[ADD] hr_personal_equipment: added module to manage employee personal…
Browse files Browse the repository at this point in the history
… equipment
  • Loading branch information
albariera committed Jul 22, 2021
1 parent 13cd7a6 commit ec24d3b
Show file tree
Hide file tree
Showing 19 changed files with 1,128 additions and 0 deletions.
91 changes: 91 additions & 0 deletions hr_personal_equipment/README.rst
@@ -0,0 +1,91 @@
=====================
Hr Personal Equipment
=====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-tegin%2Fhr-lightgray.png?logo=github
:target: https://github.com/tegin/hr/tree/12.0/hr_personal_equipment
:alt: tegin/hr

|badge1| |badge2| |badge3|

This module allows to create a personal equipment request and manage allocation of employee personal equipment.

**Table of contents**

.. contents::
:local:

Installation
============

To install this module, you need to have HR module installed or it will be requested during installation.

Usage
=====

First, products which can be requested by employees should be marked as employee personal equipment.
1. Go to *Products* (In *Inventory* App for example).
2. Select a product.
3. Mark the *Is Employee Personal Equipment* flag.(An additional page appears which serves as a hook if additional fields are needed).

To create a personal equipment request, a common user should follow the next steps:
1. Go to menu *Employees -> Personal Equipment-> Employee Personal Equipment Request*
2. Current employee is set as default. (An Hr Officer can change the employee if needed).
3. At *Personal Equipment* select the equipments you want to request.
4. Add "Observations" at *Observations* if desired.

Then, an HR Manager should:
1. If everything is correct, "Accept" the request.
2. Finally, when the equipment is given to the employee, the allocation should be validated. This can be done in two ways:
a) Click the allocation in the equipment request that you want to validate, the form view will be opened, and click "Validate".
b) Go to *Employees -> Personal Equipment-> Allocations*. Select the corresponding allocation and click "Validate".

A common user can only see its own allocations. The HR Officer can see all of them.

If needed, the allocation can be expired clicking the button "Expire", which can be found at the allocation form view.

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

Bugs are tracked on `GitHub Issues <https://github.com/tegin/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 <https://github.com/tegin/hr/issues/new?body=module:%20hr_personal_equipment%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Creu Blanca

Contributors
~~~~~~~~~~~~

* Alba Riera <alba.riera@creublanca.es>

Other credits
~~~~~~~~~~~~~



Maintainers
~~~~~~~~~~~

This module is part of the `tegin/hr <https://github.com/tegin/hr/tree/12.0/hr_personal_equipment>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions hr_personal_equipment/__init__.py
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions hr_personal_equipment/__manifest__.py
@@ -0,0 +1,21 @@
# Copyright 2021 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Hr Personal Equipment',
'summary': """
This addon allows to manage employee personal equipment""",
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'author': 'Creu Blanca,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/hr',
'depends': ["product", "hr", "mail"],
'data': [
'security/hr_personal_equipment_security.xml',
'security/ir.model.access.csv',
'views/product_template.xml',
'views/hr_personal_equipment.xml',
'views/hr_personal_equipment_request.xml',
],
'demo': [],
}
3 changes: 3 additions & 0 deletions hr_personal_equipment/models/__init__.py
@@ -0,0 +1,3 @@
from . import product_template
from . import hr_personal_equipment
from . import hr_personal_equipment_request
69 changes: 69 additions & 0 deletions hr_personal_equipment/models/hr_personal_equipment.py
@@ -0,0 +1,69 @@
# Copyright 2021 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _


class HrPersonalEquipment(models.Model):

_name = 'hr.personal.equipment'
_description = 'Adds personal equipment information and allocation'
_inherit = ["mail.thread", "mail.activity.mixin"]

name = fields.Char(compute='_compute_name')
product_id = fields.Many2one(comodel_name='product.product', required=True,
domain=[('is_personal_equipment', '=', True)])
employee_id = fields.Many2one(comodel_name='hr.employee',
related="equipment_request_id.employee_id",
store=True)
state = fields.Selection([("draft", "Draft"),
("accepted", "Accepted"),
("valid", "Valid"),
("expired", "Expired"),
("cancelled", "Cancelled")],
default="draft", track_visibility=True)
start_date = fields.Date()
equipment_request_id = fields.Many2one(comodel_name="hr.personal.equipment.request",
required=True, ondelete='cascade')
quantity = fields.Integer(default=1)
product_uom_id = fields.Many2one(
"uom.uom",
"Unit of Measure"
)

@api.onchange('product_id')
def _onchange_uom_id(self):
if self.product_id:
self.product_uom_id = self.product_id.uom_id
return {'domain':
{'product_uom_id':
[('category_id', '=', self.product_uom_id.category_id.id)]
}
}

@api.depends('product_id', 'employee_id')
def _compute_name(self):
for rec in self:
if rec.product_id.name and rec.employee_id.name:
rec.name = "{} to {}".format(rec.product_id.name, rec.employee_id.name)

def _validate_allocation_vals(self):
return {
'state': 'valid',
'start_date': fields.Date.context_today(self) if not self.start_date else self.start_date,
}

def validate_allocation(self):
for rec in self:
rec.write(rec._validate_allocation_vals())

def expire_allocation(self):
for rec in self:
rec.state = 'expired'

def _accept_request_vals(self):
return {'state': 'accepted'}

def _accept_request(self):
for rec in self:
rec.write(rec._accept_request_vals())
48 changes: 48 additions & 0 deletions hr_personal_equipment/models/hr_personal_equipment_request.py
@@ -0,0 +1,48 @@
# Copyright 2021 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _


class HrPersonalEquipmentRequest(models.Model):

_name = 'hr.personal.equipment.request'
_description = 'This model allows to create a personal equipment request'
_inherit = ['mail.thread', 'mail.activity.mixin']

name = fields.Char(compute="_compute_name")
employee_id = fields.Many2one(
comodel_name="hr.employee", string="Employee", required=True,
default=lambda self: self._default_employee_id()
)
line_ids = fields.One2many(string="Personal Equipment",
comodel_name="hr.personal.equipment",
inverse_name="equipment_request_id", copy=True)
state = fields.Selection([("draft", "Draft"),
("accepted", "Accepted"),
("cancelled", "Cancelled")],
default='draft', track_visibility=True)
observations = fields.Text()

def _default_employee_id(self):
return self.env.user.employee_ids[:1]

@api.depends("employee_id")
def _compute_name(self):
for rec in self:
rec.name = _("Personal Equipment Request by %s") % rec.employee_id.name

def accept_request(self):
for rec in self:
rec.write(rec._accept_request_vals())
rec.line_ids._accept_request()

def _accept_request_vals(self):
return {
"state": "accepted"
}

def cancel_request(self):
for rec in self:
rec.state = 'cancelled'
rec.line_ids.update({'state': 'cancelled'})
12 changes: 12 additions & 0 deletions hr_personal_equipment/models/product_template.py
@@ -0,0 +1,12 @@
# Copyright 2021 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductTemplate(models.Model):

_inherit = 'product.template'

is_personal_equipment = fields.Boolean(default=False,
string="Is Employee Personal Equipment")
1 change: 1 addition & 0 deletions hr_personal_equipment/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Alba Riera <alba.riera@creublanca.es>
1 change: 1 addition & 0 deletions hr_personal_equipment/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
This module allows to create a personal equipment request and manage allocation of employee personal equipment.
20 changes: 20 additions & 0 deletions hr_personal_equipment/readme/USAGE.rst
@@ -0,0 +1,20 @@
First, products which can be requested by employees should be marked as employee personal equipment.
1. Go to *Products* (In *Inventory* App for example).
2. Select a product.
3. Mark the *Is Employee Personal Equipment* flag.(An additional page appears which serves as a hook if additional fields are needed).

To create a personal equipment request, a common user should follow the next steps:
1. Go to menu *Employees -> Personal Equipment-> Employee Personal Equipment Request*
2. Current employee is set as default. (An Hr Officer can change the employee if needed).
3. At *Personal Equipment* select the equipments you want to request.
4. Add "Observations" at *Observations* if desired.

Then, an HR Manager should:
1. If everything is correct, "Accept" the request.
2. Finally, when the equipment is given to the employee, the allocation should be validated. This can be done in two ways:
a) Click the allocation in the equipment request that you want to validate, the form view will be opened, and click "Validate".
b) Go to *Employees -> Personal Equipment-> Allocations*. Select the corresponding allocation and click "Validate".

A common user can only see its own allocations. The HR Officer can see all of them.

If needed, the allocation can be expired clicking the button "Expire", which can be found at the allocation form view.
37 changes: 37 additions & 0 deletions hr_personal_equipment/security/hr_personal_equipment_security.xml
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="personal_equipment_request_only_self_user" model="ir.rule">
<field name="name">Access only self user's employee personal equipment request</field>
<field name="model_id" ref="model_hr_personal_equipment_request"/>
<field name="domain_force">[('employee_id', 'in', user.employee_ids.ids)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="personal_equipment_request_all_manager" model="ir.rule">
<field name="name">Access all employee personal equipment request</field>
<field name="model_id" ref="model_hr_personal_equipment_request"/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('hr.group_hr_user'))]"/>
</record>
<record id="personal_equipment_only_self_user" model="ir.rule">
<field name="name">Access only self user's employee personal equipment</field>
<field name="model_id" ref="model_hr_personal_equipment"/>
<field name="domain_force">[('equipment_request_id.employee_id', 'in', user.employee_ids.ids)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="personal_equipment_all_manager" model="ir.rule">
<field name="name">Access all employee personal equipment</field>
<field name="model_id" ref="model_hr_personal_equipment"/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('hr.group_hr_user'))]"/>
</record>
<record id="personal_equipment_draft_state" model="ir.rule">
<field name="name">Delete employee personal equipment only in draft state</field>
<field name="model_id" ref="model_hr_personal_equipment"/>
<field name="domain_force">[('state', '=', 'draft')]</field>
<field name="global" eval="True"/>
<field name="perm_create" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_read" eval="False"/>
<field name="perm_unlink" eval="True"/>
</record>
</odoo>
6 changes: 6 additions & 0 deletions hr_personal_equipment/security/ir.model.access.csv
@@ -0,0 +1,6 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
acl_hr_personal_equipment_officer,hr_personal_equipment_officer,model_hr_personal_equipment,hr.group_hr_user,1,1,1,1
acl_hr_personal_equipment_user,hr_personal_equipment_user,model_hr_personal_equipment,base.group_user,1,1,1,1
acl_hr_personal_equipment_request_officer,hr_personal_equipment_request_officer,model_hr_personal_equipment_request,hr.group_hr_user,1,1,1,0
acl_hr_personal_equipment_request_user,hr_personal_equipment_request_user,model_hr_personal_equipment_request,base.group_user,1,1,1,0

Binary file added hr_personal_equipment/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ec24d3b

Please sign in to comment.