Skip to content

Commit

Permalink
Added leave banks module
Browse files Browse the repository at this point in the history
  • Loading branch information
dufresnedavid committed Nov 11, 2014
1 parent acea783 commit e6c6d37
Show file tree
Hide file tree
Showing 16 changed files with 1,151 additions and 0 deletions.
28 changes: 28 additions & 0 deletions hr_leave_banks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Odoo Canada. 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_bank,
hr_leave_bank_line,
hr_leave_bank_template,
hr_leave_bank_template_line,
hr_payslip,
hr_employee,
)
64 changes: 64 additions & 0 deletions hr_leave_banks/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Odoo Canada. 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 Banks',
'category': 'Localization',
'version': '1.0',
'license': 'AGPL-3',
'category': 'Generic Modules/Human Resources',
'description': """
Leave Banks
===========
Adds leave banks on employees.
Whenever a payslip of an employee is computed, the related leave bank records
are writen.
Each leave bank is related to a leave bank template. Templates indicate whitch
rules are sumed or substracted from the bank each time a payslip is computed.
When a payslip line is deleted, related leave bank lines are deleted
so the total amount remains correct.
This module does not and should never have any data but only the mecanic
that allows to compute leave banks lines. The reason is that each country
might have different needs.
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',
'hr_employee_view.xml',
'hr_leave_bank_view.xml',
'hr_leave_bank_template_view.xml',
],
'test': [],
'demo': [],
'installable': True,
}
50 changes: 50 additions & 0 deletions hr_leave_banks/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Odoo Canada. 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_bank_ids': fields.one2many(
'hr.leave.bank',
'employee_id',
'Leave Banks',
),
}

def get_leave_bank(
self, cr, uid, employee_id, leave_code, context=None
):
"""
Get a leave bank of an employee that matches a leave_code
return: a leave bank browse record
"""
employee = self.browse(cr, uid, employee_id, context=context)
leave_banks = employee.leave_bank_ids

for bank in leave_banks:
if bank.code == leave_code:
return bank.id

return False
22 changes: 22 additions & 0 deletions hr_leave_banks/hr_employee_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_employee_form" model="ir.ui.view">
<field name="name">hr.employee.form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page name="payroll_page" string="Leave Banks">
<field name="leave_bank_ids">
<tree>
<field name="name"/>
<field name="total" string="Amount"/>
</tree>
</field>
</page>
</notebook>
</field>
</record>
</data>
</openerp>
111 changes: 111 additions & 0 deletions hr_leave_banks/hr_leave_bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Odoo Canada. 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_leave_bank(orm.Model):
"""
An instance of a leave bank for an employee
"""
_name = 'hr.leave.bank'
_description = 'Employee Leave Bank'

def _get_approved_lines(
self, cr, uid, ids, context=None
):
"""
Gets lines of leave banks entered mannually plus those
related to an approved payslip
return: a dict that contains a list of bank line objects
for each bank id
"""
result = {}
if not ids:
return result

if isinstance(ids, (int, long)):
ids = [ids]

banks = self.browse(cr, uid, ids, context=context)

return {
bank.id:
[
line for line in bank.line_ids
# Lines entered manually or from approved payslip
if not line.payslip_id or line.state in ['done']
]
for bank in banks
}

def _sum_lines(
self, cr, uid, ids, field_names, arg=None, context=None
):
approved_lines = self._get_approved_lines(
cr, uid, ids, context=context
)
return {
bank_id: reduce(
lambda x, y: x + y.amount,
approved_lines[bank_id],
0
)
for bank_id in approved_lines
}

_columns = {
'name': fields.related(
'template_id',
'name',
type="char",
string='Leave Bank',
),
'code': fields.related(
'template_id',
'code',
type="char",
string='Code',
),
'employee_id': fields.many2one(
'hr.employee',
'Employee',
required=True,
ondelete='cascade',
),
'template_id': fields.many2one(
'hr.leave.bank.template',
'Bank Template',
required=True,
),
'line_ids': fields.one2many(
'hr.leave.bank.line',
'bank_id',
string='Bank Lines',
),
'total': fields.function(
_sum_lines,
method=True,
type="float",
string='Total',
),
}
104 changes: 104 additions & 0 deletions hr_leave_banks/hr_leave_bank_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# -*- coding:utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Odoo Canada. 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_leave_bank_line(orm.Model):
"""
There are two types of leave bank lines for now.
- Those entered manually
- Those related to a payslip
If it is related to a payslip, the payslip needs to be approved
for the line to be considered in the bank's total.
"""
_name = 'hr.leave.bank.line'
_description = 'Leave Bank Line'
_columns = {
# Mandatory fields
'bank_id': fields.many2one(
'hr.leave.bank',
'Leave Bank',
ondelete='cascade',
required=True,
),
'amount': fields.float(
'Amount',
required=True,
),
'category': fields.selection(
[
('add', 'Allowance added to the bank'),
('substract', 'Allowance taken by the employee'),
],
string="Category",
required=True,
),
'type': fields.selection(
[
('payslip', 'Payslip Line'),
('manual', 'Entered Manually'),
],
type='char',
string="Type",
required=True,
),

# Fields required when line is related to a payslip line
'payslip_id': fields.many2one(
'hr.payslip',
'Payslip',
ondelete='cascade',
),
'payslip_line_id': fields.many2one(
'hr.payslip.line',
'Payslip Line',
ondelete='cascade',
),
'state': fields.related(
'payslip_id',
'state',
type="char",
string="State"
),
'salary_rule_id': fields.related(
'payslip_line_id',
'salary_rule_id',
type="many2one",
relation='hr.salary.rule',
string="Salary Rule",
),

# Fields required when the line is entered manually
'date': fields.date(
'Date',
),
'description': fields.char(
'Description',
)
}
_defaults = {
'payslip_id': False,
'payslip_line_id': False,
'category': 'add',
'type': 'manual',
}
Loading

0 comments on commit e6c6d37

Please sign in to comment.