diff --git a/hr_holidays_usability/__init__.py b/hr_holidays_usability/__init__.py index 0b8dc8c..d79f2a1 100644 --- a/hr_holidays_usability/__init__.py +++ b/hr_holidays_usability/__init__.py @@ -1,24 +1,4 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# HR Holidays Usability module for Odoo -# Copyright (C) 2015 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- from . import hr_holidays from . import wizard diff --git a/hr_holidays_usability/__openerp__.py b/hr_holidays_usability/__openerp__.py index 1362a6e..bad95c5 100644 --- a/hr_holidays_usability/__openerp__.py +++ b/hr_holidays_usability/__openerp__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # HR Holidays Usability module for Odoo diff --git a/hr_holidays_usability/hr_holidays.py b/hr_holidays_usability/hr_holidays.py index af84f09..f963d02 100644 --- a/hr_holidays_usability/hr_holidays.py +++ b/hr_holidays_usability/hr_holidays.py @@ -22,6 +22,7 @@ from openerp import models, fields, api, _ from openerp.exceptions import ValidationError +from openerp.exceptions import Warning as UserError from datetime import datetime from dateutil.relativedelta import relativedelta import pytz @@ -39,6 +40,11 @@ class HrHolidaysStatus(models.Model): # TODO find proper English translation ], string='Vacation Compute Method', required=True, default='worked') + add_validation_manager = fields.Boolean( + string='Allocation validated by HR Manager', + help="If enabled, allocation requests for this leave type " + "can be validated only by an HR Manager " + "(not possible by an HR Officer).") class HrEmployee(models.Model): @@ -338,6 +344,34 @@ class HrHolidays(models.Model): obj.number_of_days_temp = days return res + @api.multi + def holidays_validate(self): + for holi in self: + if holi.user_id == self.env.user: + if holi.type == 'remove': + raise UserError(_( + "You cannot validate your own Leave request '%s'.") + % holi.name) + elif ( + holi.type == 'add' and + not self.pool['res.users'].has_group( + self._cr, self._uid, 'base.group_hr_manager')): + raise UserError(_( + "You cannot validate your own Allocation " + "request '%s'.") + % holi.name) + if ( + holi.type == 'add' and + holi.holiday_status_id.add_validation_manager and + not self.pool['res.users'].has_group( + self._cr, self._uid, 'base.group_hr_manager')): + raise UserError(_( + "Allocation request '%s' has a leave type '%s' that " + "can be approved only by an HR Manager.") + % (holi.name, holi.holiday_status_id.name)) + res = super(HrHolidays, self).holidays_validate() + return res + class ResCompany(models.Model): _inherit = 'res.company' diff --git a/hr_holidays_usability/hr_holidays_mail.xml b/hr_holidays_usability/hr_holidays_mail.xml index 985a8ed..49835ff 100644 --- a/hr_holidays_usability/hr_holidays_mail.xml +++ b/hr_holidays_usability/hr_holidays_mail.xml @@ -9,7 +9,7 @@ 'dbname': cr.dbname, }) template_id=self.pool.get('ir.model.data').get_object_reference(cr, uid, 'hr_holidays_usability', 'email_template_hr_holidays')[1] -self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force_send=True, context=context) +self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, context=context) code ir.actions.server @@ -23,7 +23,7 @@ self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force 'dbname': cr.dbname, }) template_id=self.pool.get('ir.model.data').get_object_reference(cr, uid, 'hr_holidays_usability', 'email_template_hr_holidays')[1] -self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force_send=True, context=context) +self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, context=context) code ir.actions.server @@ -37,7 +37,7 @@ self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force 'dbname': cr.dbname, }) template_id=self.pool.get('ir.model.data').get_object_reference(cr, uid, 'hr_holidays_usability', 'email_template_hr_holidays')[1] -self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force_send=True, context=context) +self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, context=context) code ir.actions.server @@ -70,10 +70,10 @@ self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force
% if ctx.get('dbname') and 'prod' not in ctx.get('dbname'): -

WARNING : THIS IS A TEST E-MAIL sent from a test OpenERP database (${ctx.get('dbname')}). Do not take into account !

+

WARNING : THIS IS A TEST E-MAIL sent from a test Odoo database (${ctx.get('dbname')}). Do not take into account !

% endif -

The following ${object.type == 'remove' and 'leave request' or 'ALLOCATION request (i.e. credit of days, not debit !)'} has been ${ctx.get('wkf_tracker') or 'ERROR'} today in OpenERP by ${user.name or ''} :

+

The following ${object.type == 'remove' and 'leave request' or 'ALLOCATION request (i.e. credit of days, not debit !)'} has been ${ctx.get('wkf_tracker') or 'ERROR'} today in Odoo by ${user.name or ''} :

  • Employee : ${object.employee_id.name or ''}
  • @@ -102,7 +102,7 @@ self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force % endif

    --
    -Automatic e-mail sent by OpenERP. Do not reply.
    +Automatic e-mail sent by Odoo. Do not reply.
    Database : ${ctx.get('dbname')}

diff --git a/hr_holidays_usability/hr_holidays_view.xml b/hr_holidays_usability/hr_holidays_view.xml index 6c92eae..e86c10d 100644 --- a/hr_holidays_usability/hr_holidays_view.xml +++ b/hr_holidays_usability/hr_holidays_view.xml @@ -120,6 +120,9 @@ hr_holidays.edit_holiday_new is used for both leaves and allocation --> + + + diff --git a/hr_holidays_usability/security/holiday_security.xml b/hr_holidays_usability/security/holiday_security.xml index 1659ffa..1023bd9 100644 --- a/hr_holidays_usability/security/holiday_security.xml +++ b/hr_holidays_usability/security/holiday_security.xml @@ -1,19 +1,44 @@ - + + + Personal Holiday Counters - ['|',('employee_id.user_id','=',user.id),('employee_id.user_id','=',False)] + [('employee_id.user_id','=',user.id)] + + My Holiday Counter and Subordinates + + ['|', ('employee_id.user_id','=',user.id), ('employee_id','child_of',user.employee_ids.ids)] + + + All Holiday Counters [(1,'=',1)] - + + + + + + ['|', ('employee_id.user_id','=',user.id), ('employee_id','child_of',user.employee_ids.ids)] + + + + HR Manager can see all Holidays + + [(1,'=',1)] + diff --git a/hr_holidays_usability/wizard/hr_holidays_mass_allocation.py b/hr_holidays_usability/wizard/hr_holidays_mass_allocation.py index 497e181..adcc7ae 100644 --- a/hr_holidays_usability/wizard/hr_holidays_mass_allocation.py +++ b/hr_holidays_usability/wizard/hr_holidays_mass_allocation.py @@ -88,5 +88,6 @@ class HrHolidaysMassAllocation(models.TransientModel): 'target': 'current', 'domain': [('id', 'in', alloc_hol_ids)], 'nodestroy': True, + 'context': "{'default_type':'add'}", }) return action