Skip to content

Commit

Permalink
Merge branch 'new-hr_holidays_working_time_leaves_revaluation-jne' of…
Browse files Browse the repository at this point in the history
… github.com:acsone/acsone-addons into lis_master
  • Loading branch information
adrienpeiffer committed Aug 24, 2016
2 parents 4059292 + f41b656 commit 6bf5bc4
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 0 deletions.
27 changes: 27 additions & 0 deletions hr_holidays_leaves_revaluation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. 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 Holidays Leaves Revaluation
==============================
This module adds menu entry that allows to launch a wizard to control
the number of available holidays per type and per employee. It also
allows to decrease this number depending of a maximum allowed days

Credits
=======

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

* Jonathan Nemry <jonathan.nemry@acsone.eu>

Maintainer
----------

.. image:: https://www.acsone.eu/logo.png
:alt: ACSONE SA/NV
:target: http://www.acsone.eu

This module is maintained by ACSONE SA/NV.
6 changes: 6 additions & 0 deletions hr_holidays_leaves_revaluation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizard
23 changes: 23 additions & 0 deletions hr_holidays_leaves_revaluation/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "HR Holidays Leaves Revaluation",

'summary': """
This module adds menu entry that allows to launch a wizard to control
the number of available holidays per type and per employee. It also
allows to decrease this number depending of a maximum allowed days""",
'author': 'ACSONE SA/NV',
'website': "http://acsone.eu",
'category': 'HR',
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'hr_holidays',
'hr_holidays_working_time',
],
'data': [
'wizard/hr_holidays_leaves_revaluation_wizard_view.xml',
],
}
5 changes: 5 additions & 0 deletions hr_holidays_leaves_revaluation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import hr_holidays
20 changes: 20 additions & 0 deletions hr_holidays_leaves_revaluation/models/hr_holidays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models


class HrHolidays(models.Model):

_inherit = 'hr.holidays'

is_revaluation = fields.Boolean()

_sql_constraints = [
('date_check3_hours',
"CHECK ( number_of_hours_temp >= 0 OR is_revaluation = True)",
"The number of hours must be greater than 0."),
('date_check',
"CHECK ( number_of_days_temp >= 0 OR is_revaluation = True)",
"The number of days must be greater than 0."),
]
2 changes: 2 additions & 0 deletions hr_holidays_leaves_revaluation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_hr_holidays_leaves_revaluation
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests import common
from openerp import fields
import datetime
from datetime import date


class TestHrHolidaysLeavesRevaluation(common.TransactionCase):

def setUp(self):
super(TestHrHolidaysLeavesRevaluation, self).setUp()
self.res_partner_mod = self.env['res.partner']
self.res_users_mod = self.env['res.users']
self.hr_employee_mod = self.env['hr.employee']
self.hr_holidays_mod = self.env['hr.holidays']
self.hr_holidays_satus_mod = self.env['hr.holidays.status']
self.hr_holidays_leaves_revaluation_mod =\
self.env['hr.holidays.leaves.revaluation']

def test_hr_holidays_leaves_revaluation(self):
vals = {
'name': 'name',
'email': 'name@email.com',
}
partner_id = self.res_partner_mod.create(vals)
vals = {
'partner_id': partner_id.id,
'login': 'login',
}
user_id = self.res_users_mod.create(vals)
vals = {
'name': 'name',
'user_id': user_id.id,
}
emp_id = self.hr_employee_mod.create(vals)
holiday_status_id = self.hr_holidays_satus_mod.search([], limit=1)
self.assertTrue(
holiday_status_id, 'Should have at least one leave type')
base = 42
revaluated = 25
date_f = date.today() - datetime.timedelta(days=1)
vals = {
'name': 'Legal leaves 2042',
'employee_id': emp_id.id,
'holiday_status_id': holiday_status_id.id,
'number_of_hours_temp': base,
'type': 'add',
'date_from': fields.Date.to_string(date_f),
}
allocation_id = self.hr_holidays_mod.create(vals)
allocation_id.signal_workflow('validate')
date_t = date.today() + datetime.timedelta(days=1)
vals = {
'check_point_date': fields.Date.to_string(date_t),
'max_nb_hours_allowed': revaluated,
'holiday_status_id': holiday_status_id.id,
}
wiz_id = self.hr_holidays_leaves_revaluation_mod.create(vals)
wiz_id.button_leaves_revaluation()
domain = [
('number_of_days_temp', '<', 0),
('type', '=', 'add'),
('holiday_status_id', '=', holiday_status_id.id),
]
revaluate_holidays_id = self.hr_holidays_mod.search(domain, limit=1)
self.assertTrue(revaluate_holidays_id, 'Should find one')
self.assertEquals(
revaluate_holidays_id.state, 'confirm',
'should be in state confirm')
5 changes: 5 additions & 0 deletions hr_holidays_leaves_revaluation/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import hr_holidays_leaves_revaluation
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, models, fields


class HrHolidaysLeavesRevaluation(models.TransientModel):
_name = 'hr.holidays.leaves.revaluation'
_description = 'Hr Holidays Leaves Revaluation'

@api.model
def _get_revaluate_vals(self, employee_id, nb_hours):
print nb_hours
return {
'name': 'Revaluation',
'employee_id': employee_id,
'holiday_status_id': self.holiday_status_id.id,
'number_of_hours_temp': nb_hours,
'type': 'add',
'is_revaluation': True,
}

check_point_date = fields.Date(required=True)
max_nb_hours_allowed = fields.Float(
string='Maximum Number of hours allowed', required=True)
holiday_status_id = fields.Many2one(
comodel_name='hr.holidays.status', string='Leave Type', required=True)

@api.multi
def _get_sql_command(self):
self.ensure_one()
return """
SELECT
employee_id,
holiday_status_id,
sum(number_of_hours) as nb_remaining_hours
FROM hr_holidays
WHERE
((type = 'add' AND
state = 'validate')
or
(type = 'remove' AND
state not in ('refuse', 'cancel')
AND
date_from <= '%s'
))
AND holiday_status_id = %s
GROUP BY employee_id,holiday_status_id;
""" % (
self.check_point_date, self.holiday_status_id.id)

@api.multi
def button_leaves_revaluation(self):
self.ensure_one()
hr_holidays_model = self.env['hr.holidays']
self.env.cr.execute(self._get_sql_command())
for v in self.env.cr.dictfetchall():
if v['nb_remaining_hours'] > self.max_nb_hours_allowed:
nb_hours_temp =\
self.max_nb_hours_allowed - v['nb_remaining_hours']
hr_holidays_model.create(self._get_revaluate_vals(
v['employee_id'], nb_hours_temp))
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="hr_holidays_leave_revaluation_wizard" model="ir.ui.view">
<field name="name">hr.holidays.leaves.revaluation.form</field>
<field name="model">hr.holidays.leaves.revaluation</field>
<field name="arch" type="xml">
<form string="Leaves Revalution" version="7.0">

<group name="data">
<field name="check_point_date"/>
<field name="max_nb_hours_allowed" />
<field name="holiday_status_id" />
</group>
<footer>
<button name="button_leaves_revaluation"
string="Ok" type="object"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>

</form>
</field>
</record>

<record id="hr_holidays_leaves_revaluation_action" model="ir.actions.act_window">
<field name="name">Leaves Revaluation</field>
<field name="res_model">hr.holidays.leaves.revaluation</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<menuitem id="hr_holidays_leaves_revaluation_menu" parent="hr_holidays.menu_open_ask_holidays"
sequence="50" action="hr_holidays_leaves_revaluation_action"/>

</data>
</openerp>

0 comments on commit 6bf5bc4

Please sign in to comment.