Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added leave accruals module #34

Merged
merged 3 commits into from
Feb 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions hr_leave_accruals/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Leave Accruals
==============

This module adds leave accruals on employees and a mechanism to compute these
automaticaly.

The amounts for a leave type can be accruded
in cash, in hours or both.


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

Nothing to do except install the module


Configuration
=============

- Go to: Human Ressources -> Configuration -> Leaves Types
- Select a leave type over which you wish to accrued amounts.
- In the form view, go to the "Leave Accruals" tab.
- Select payslip lines over which the leave type will be accruded.
- If a salary rule gives a positive amount and you need to decrease the leave accrual from this amount,
you need to set the field "Substract Amount" True.

The leave allocation system may be used to increase the hours accruded for a leave type.
For this, the field "Increase Accruals on Allocations" on the leave type must be True.
An example of use for this feature is for sick leaves.


Usage
=====

Compute your payslips and the amounts are automatically accruded in the related employee leave accrual.
In the employee form, there is a tab "Leave Accruals", which shows amounts accruded per leave type.


Known issues / Roadmap
======================

None


Credits
=======

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

.. image:: http://sflx.ca/logo
:alt: Savoir-faire Linux
:target: http://sflx.ca

* David Dufresne <david.dufresne@savoirfairelinux.com>
* Maxime Chambreuil <maxime.chambreuil@savoirfairelinux.com>
* Pierre Lamarche <pierre.lamarche@savoirfairelinux.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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 http://odoo-community.org.
30 changes: 30 additions & 0 deletions hr_leave_accruals/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Savoir-faire Linux. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import (
hr_leave_accrual,
hr_leave_accrual_line,
hr_holidays,
hr_holidays_status,
hr_holidays_status_accrual_line,
hr_payslip,
hr_employee,
res_company,
)
52 changes: 52 additions & 0 deletions hr_leave_accruals/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 - 2015 Savoir-faire Linux. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

{
'name': 'Leave Accruals',
'version': '1.0',
'license': 'AGPL-3',
'category': 'Generic Modules/Human Resources',
'description': """
Leave Accruals
==============
This module adds leave accruals on employees and a mechanism to compute these
automaticaly.

Contributors
------------
* David Dufresne <david.dufresne@savoirfairelinux.com>
* Pierre Lamarche <pierre.lamarche@savoirfairelinux.com>
""",
'author': 'Savoir-faire Linux',
'website': 'https://www.savoirfairelinux.com/',
'depends': [
'hr_payroll',
],
'data': [
'security/ir.model.access.csv',
'view/hr_employee_view.xml',
'view/hr_leave_accrual_view.xml',
'view/hr_holidays_status_view.xml',
'view/res_company_view.xml',
],
'test': ['test/hr_leave_accruals_test.yml'],
'demo': [],
'installable': True,
}
68 changes: 68 additions & 0 deletions hr_leave_accruals/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Savoir-faire Linux. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm, fields


class hr_employee(orm.Model):
_name = 'hr.employee'
_inherit = 'hr.employee'
_columns = {
'leave_accrual_ids': fields.one2many(
'hr.leave.accrual',
'employee_id',
'Leave Accruals',
),
}

def get_leave_accrual_id(
self, cr, uid, employee_id, accrual_code=False,
leave_type_id=False, context=None
):
"""
Get a leave accrual of an employee that matches a leave_code
:return: the id of a leave accrual
"""
employee = self.browse(cr, uid, employee_id, context=context)

accrual_id = False

for accrual in employee.leave_accrual_ids:
if accrual_code and accrual.code == accrual_code \
or leave_type_id == accrual.leave_type_id.id:
accrual_id = accrual.id
break

# If the employee doesn't have the accrual of the given type,
# create it
if not accrual_id:
if accrual_code:
leave_type_id = self.pool['hr.holidays.status'].search(
cr, uid, [('accrual_code', '=', accrual_code)],
context=context)[0]

accrual_id = self.pool['hr.leave.accrual'].create(
cr, uid, {
'employee_id': employee_id,
'leave_type_id': leave_type_id,
}, context=context)

return accrual_id
88 changes: 88 additions & 0 deletions hr_leave_accruals/hr_holidays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Savoir-faire Linux. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from datetime import datetime


class hr_holidays(orm.Model):
_inherit = 'hr.holidays'

_columns = {
'accrual_line_id': fields.one2many(
'hr.leave.accrual.line',
'allocation_id',
string="Leave Accrual Line",
),
}

def holidays_validate(self, cr, uid, ids, context=None):
"""
After an allocation of holidays is validated,
add hours to the related leave accrual of the employee
"""
res = super(hr_holidays, self).holidays_validate(
cr, uid, ids, context=context)

for leave in self.browse(cr, uid, ids, context=context):
if leave.type == 'add' and leave.holiday_type == 'employee' \
and leave.holiday_status_id.increase_accrual_on_allocation:

employee = leave.employee_id
leave_type_id = leave.holiday_status_id.id

accrual_id = self.pool['hr.employee'].get_leave_accrual_id(
cr, uid, employee.id, leave_type_id=leave_type_id,
context=context)

number_of_hours = leave.number_of_days_temp * \
employee.company_id.holidays_hours_per_day

for line in leave.accrual_line_id:
line.unlink()

leave.write({
'accrual_line_id': [(0, 0, {
'source': 'allocation',
'amount': number_of_hours,
'accrual_id': accrual_id,
'date': datetime.now().strftime(
DEFAULT_SERVER_DATE_FORMAT),
'description': leave.name,
'amount_type': 'hours',
})]})

return res

def holidays_refuse(self, cr, uid, ids, context=None):
"""
After an allocation of holidays is refused,
remove the leave accrual line related
"""
res = super(hr_holidays, self).holidays_refuse(
cr, uid, ids, context=context)

for leave in self.browse(cr, uid, ids, context=context):
for line in leave.accrual_line_id:
line.unlink()

return res
42 changes: 42 additions & 0 deletions hr_leave_accruals/hr_holidays_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 - 2015 Savoir-faire Linux. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm, fields


class hr_holidays_status(orm.Model):
_inherit = 'hr.holidays.status'

_columns = {
'accrual_code': fields.char(
'Accrual Code',
),
'increase_accrual_on_allocation': fields.boolean(
'Increase Accruals on Allocations',
help="Add hours to the related leave accruals when allocating "
"leaves to employees."
),
'accrual_line_ids': fields.one2many(
'hr.holidays.status.accrual.line',
'leave_type_id',
'Accrual Lines',
),
}
Loading