Introduce new wizard and counters

This commit is contained in:
Alexis de Lattre
2015-06-12 00:06:36 +02:00
parent 7831277c14
commit 7a07d438e4
14 changed files with 349 additions and 20 deletions

View File

@@ -22,3 +22,4 @@
from . import hr_holidays from . import hr_holidays
from . import wizard from . import wizard
from . import report

View File

@@ -33,9 +33,14 @@
'depends': ['hr_holidays', 'hr_public_holidays'], 'depends': ['hr_holidays', 'hr_public_holidays'],
'data': [ 'data': [
'wizard/hr_holidays_mass_allocation_view.xml', 'wizard/hr_holidays_mass_allocation_view.xml',
'wizard/hr_holidays_post_view.xml',
'report/hr_holidays_employee_counter_view.xml',
'hr_holidays_view.xml', 'hr_holidays_view.xml',
'hr_holidays_mail.xml', 'hr_holidays_mail.xml',
'res_company_view.xml', 'res_company_view.xml',
'hr_employee_view.xml',
'security/holiday_security.xml',
'security/ir.model.access.csv',
], ],
'installable': True, 'installable': True,
} }

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="view_employee_form_leave_inherit" model="ir.ui.view">
<field name="name">hr_holidays_usability.hr.employee.form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr_holidays.view_employee_form_leave_inherit"/>
<field name="arch" type="xml">
<group string="Leaves" position="attributes">
<attribute name="invisible">1</attribute>
</group>
</field>
</record>
</data>
</openerp>

View File

@@ -71,18 +71,7 @@ class HrHolidays(orm.Model):
# 1 for 'unpaid leaves' + repos compensateur + congés conventionnels + maladie # 1 for 'unpaid leaves' + repos compensateur + congés conventionnels + maladie
# 1 or 2 for normal holidays # 1 or 2 for normal holidays
def _compute_number_of_days(self, cr, uid, ids, name, args, context=None): def _compute_number_of_days(
result = {}
for hol in self.browse(cr, uid, ids, context=context):
if hol.type == 'remove':
# read number_of_days_remove instead of number_of_days_temp
result[hol.id] = -hol.number_of_days_remove
else:
# for allocations, we read the native field number_of_days_temp
result[hol.id] = hol.number_of_days_temp
return result
def _compute_number_of_days_remove(
self, cr, uid, ids, name, args, context=None): self, cr, uid, ids, name, args, context=None):
res = {} res = {}
# depend on the holiday_status_id # depend on the holiday_status_id
@@ -148,7 +137,18 @@ class HrHolidays(orm.Model):
break break
date_dt += relativedelta(days=1) date_dt += relativedelta(days=1)
res[hol.id] = days if hol.type == 'remove':
# read number_of_days_remove instead of number_of_days_temp
res[hol.id] = {
'number_of_days': days * -1,
'number_of_days_remove': days,
}
else:
# for allocations, we read the native field number_of_days_temp
res[hol.id] = {
'number_of_days': hol.number_of_days_temp,
'number_of_days_remove': 0,
}
return res return res
def _compute_current_leaves(self, cr, uid, ids, name, arg, context=None): def _compute_current_leaves(self, cr, uid, ids, name, arg, context=None):
@@ -201,12 +201,13 @@ class HrHolidays(orm.Model):
help="For example, if you leave one full calendar week, " help="For example, if you leave one full calendar week, "
"the end of vacation is Friday Evening"), "the end of vacation is Friday Evening"),
'number_of_days_remove': fields.function( 'number_of_days_remove': fields.function(
_compute_number_of_days_remove, _compute_number_of_days,
string="Number of Days of Vacation", string="Number of Days of Vacation", multi='holdays',
type="float", readonly=True), type="float", readonly=True),
# number_of_days is a native field that I inherit # number_of_days is a native field that I inherit
'number_of_days': fields.function( 'number_of_days': fields.function(
_compute_number_of_days, string='Number of Days', store=True), _compute_number_of_days, string='Number of Days',
multi='holdays', store=True),
'current_leaves_taken': fields.function( 'current_leaves_taken': fields.function(
_compute_current_leaves, string='Current Leaves Taken', _compute_current_leaves, string='Current Leaves Taken',
multi='usability', type='float', readonly=True), multi='usability', type='float', readonly=True),
@@ -218,7 +219,8 @@ class HrHolidays(orm.Model):
multi='usability', type='float', readonly=True), multi='usability', type='float', readonly=True),
'limit': fields.related( 'limit': fields.related(
'holiday_status_id', 'limit', type='boolean', 'holiday_status_id', 'limit', type='boolean',
string='Allow to Override Limit') string='Allow to Override Limit'),
'posted_date': fields.date('Posted Date', track_visibility='onchange'),
} }
_defaults = { _defaults = {

View File

@@ -84,7 +84,7 @@ self.pool.get('email.template').send_mail(cr, uid, template_id, object.id, force
<li>Start date : ${object.vacation_date_from or ''} ${object.vacation_time_from or ''}</li> <li>Start date : ${object.vacation_date_from or ''} ${object.vacation_time_from or ''}</li>
<li>End date : ${object.vacation_date_to or ''} ${object.vacation_time_to or ''}</li> <li>End date : ${object.vacation_date_to or ''} ${object.vacation_time_to or ''}</li>
% endif % endif
<li>Number of days : ${object.number_of_days or '0'}</li> <li>Number of days : ${object.number_of_days < 0 and object.number_of_days * -1 or object.number_of_days}</li>
<li>Leave type : ${object.holiday_status_id.name or ''}</li> <li>Leave type : ${object.holiday_status_id.name or ''}</li>
<li>Description : ${object.name or ''}</li> <li>Description : ${object.name or ''}</li>
% if object.notes: % if object.notes:

View File

@@ -35,7 +35,7 @@
<field name="vacation_time_to" on_change="vacation_to(vacation_date_to, vacation_time_to, context)" required="1"/> <field name="vacation_time_to" on_change="vacation_to(vacation_date_to, vacation_time_to, context)" required="1"/>
</field> </field>
<xpath expr="//field[@name='department_id']/.." position="after"> <xpath expr="//field[@name='department_id']/.." position="after">
<group string="Meter for this leave type" name="counters" attrs="{'invisible': [('limit', '=', True)]}"> <group string="Counter for this leave type" name="counters" attrs="{'invisible': [('limit', '=', True)]}">
<field name="limit" invisible="1"/> <field name="limit" invisible="1"/>
<label for="total_allocated_leaves"/> <label for="total_allocated_leaves"/>
<div> <div>
@@ -54,6 +54,9 @@
</div> </div>
</group> </group>
</xpath> </xpath>
<field name="department_id" position="after">
<field name="posted_date" groups="base.group_hr_user"/>
</field>
</field> </field>
</record> </record>
@@ -66,7 +69,7 @@
<attribute name="invisible">1</attribute> <attribute name="invisible">1</attribute>
</field> </field>
<field name="number_of_days" position="after"> <field name="number_of_days" position="after">
<field name="number_of_days_remove"/> <field name="number_of_days_remove" sum="Total Days of Vacation"/>
</field> </field>
<field name="date_from" position="attributes"> <field name="date_from" position="attributes">
<attribute name="invisible">1</attribute> <attribute name="invisible">1</attribute>
@@ -85,6 +88,9 @@
<field name="holiday_status_id" position="attributes"> <field name="holiday_status_id" position="attributes">
<attribute name="invisible">0</attribute> <attribute name="invisible">0</attribute>
</field> </field>
<field name="holiday_status_id" position="after">
<field name="posted_date" groups="base.group_hr_user"/>
</field>
</field> </field>
</record> </record>

View File

@@ -0,0 +1,2 @@
# -*- encoding: utf-8 -*-
from . import hr_holidays_employee_counter

View File

@@ -0,0 +1,71 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# HR Holidays Usability module for Odoo
# Copyright (C) 2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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 import tools
from openerp.osv import fields, orm
class HrHolidaysEmployeeCounter(orm.Model):
_name = 'hr.holidays.employee.counter'
_description = 'Counters for holidays of employees'
_auto = False
_rec_name = 'employee_id'
_order = 'employee_id'
_columns = {
'employee_id': fields.many2one('hr.employee', "Employee"),
'holiday_status_id': fields.many2one(
"hr.holidays.status", "Leave Type"),
'current_leaves_taken': fields.float('Current Leaves Taken'),
'current_remaining_leaves': fields.float('Current Remaining Leaves'),
'total_allocated_leaves': fields.float('Total Allocated Leaves'),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'hr_holidays_employee_counter')
cr.execute("""
CREATE or REPLACE view hr_holidays_employee_counter AS (
SELECT
min(hh.id) AS id,
hh.employee_id AS employee_id,
hh.holiday_status_id AS holiday_status_id,
sum(
CASE WHEN hh.type='remove'
THEN hh.number_of_days * -1
ELSE 0
END) AS current_leaves_taken,
sum(hh.number_of_days) AS current_remaining_leaves,
sum(
CASE WHEN hh.type = 'add'
THEN hh.number_of_days
ELSE 0
END) AS total_allocated_leaves
FROM
hr_holidays hh
JOIN hr_holidays_status hhs
ON (hhs.id=hh.holiday_status_id)
WHERE
hh.state='validate' AND
hhs.limit=False
GROUP BY hh.employee_id, hh.holiday_status_id
)
""")

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="hr_holidays_employee_counter_tree" model="ir.ui.view">
<field name="name">hr.holidays.employee.counter.tree</field>
<field name="model">hr.holidays.employee.counter</field>
<field name="arch" type="xml">
<tree string="Employee Holidays Counters">
<field name="employee_id"
invisible="not context.get('hr_holidays_employee_counter_tree_main_view')"/>
<field name="holiday_status_id"/>
<field name="current_leaves_taken"/>
<field name="current_remaining_leaves" sum="Total Remaining Leaves"/>
<field name="total_allocated_leaves"/>
</tree>
</field>
</record>
<record id="hr_holidays_employee_counter_search" model="ir.ui.view">
<field name="name">hr.holidays.employee.counter.search</field>
<field name="model">hr.holidays.employee.counter</field>
<field name="arch" type="xml">
<search>
<field name="employee_id"/>
<group string="Group By" name="groupby">
<filter name="employee_groupby" string="Employee" context="{'group_by': 'employee_id'}"/>
<filter name="holiday_status_groupby" string="Leave Type"
context="{'group_by': 'holiday_status_id'}"/>
</group>
</search>
</field>
</record>
<record id="hr_holidays_employee_counter_action" model="ir.actions.act_window">
<field name="name">Counters</field>
<field name="res_model">hr.holidays.employee.counter</field>
<field name="view_mode">tree</field>
<field name="context">{'hr_holidays_employee_counter_tree_main_view': 1}</field>
</record>
<menuitem id="hr_holidays_employee_counter_menu"
action="hr_holidays_employee_counter_action"
parent="hr_holidays.menu_open_ask_holidays"/>
</data>
</openerp>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="hr_holidays_counter_personal_rule" model="ir.rule">
<field name="name">Personal Holiday Counters</field>
<field name="model_id" ref="model_hr_holidays_employee_counter"/>
<field name="domain_force">['|',('employee_id.user_id','=',user.id),('employee_id.user_id','=',False)]</field>
</record>
<record id="hr_holidays_counter_see_all" model="ir.rule">
<field name="name">All Holiday Counters</field>
<field name="model_id" ref="model_hr_holidays_employee_counter"/>
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('base.group_hr_user'))]"/>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_hr_holidays_employee_counter,Full access on hr.holidays.employee.counter,model_hr_holidays_employee_counter,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_hr_holidays_employee_counter Full access on hr.holidays.employee.counter model_hr_holidays_employee_counter base.group_user 1 1 1 1

View File

@@ -1,2 +1,3 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
from . import hr_holidays_mass_allocation from . import hr_holidays_mass_allocation
from . import hr_holidays_post

View File

@@ -0,0 +1,103 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# HR Holidays Usability module for Odoo
# Copyright (C) 2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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.translate import _
class HrHolidaysPost(orm.TransientModel):
_name = 'hr.holidays.post'
_description = 'Wizard for post holidays'
_columns = {
'before_date': fields.date(
'Select Holidays That Ended Before', required=True,
help="The wizard will select the validated holidays "
"that ended before that date (including holidays that "
"ended on that date)."),
'holidays_to_post_ids': fields.many2many(
'hr.holidays', string='Leave Requests to Post',
domain=[
('type', '=', 'remove'),
('holiday_type', '=', 'employee'),
('state', '=', 'validate'),
('posted_date', '=', False),
]),
'state': fields.selection([
('draft', 'Draft'),
('done', 'Done'),
], 'State', readonly=True),
}
_defaults = {
'before_date': fields.date.context_today,
'state': 'draft',
}
def select_date(self, cr, uid, ids, context=None):
assert len(ids) == 1, 'Only 1 ID'
wiz = self.browse(cr, uid, ids[0], context=context)
hol_ids = self.pool['hr.holidays'].search(cr, uid, [
('type', '=', 'remove'),
('holiday_type', '=', 'employee'),
('state', '=', 'validate'),
('posted_date', '=', False),
('vacation_date_to', '<=', wiz.before_date),
], context=context)
self.write(cr, uid, ids, {
'state': 'done',
'holidays_to_post_ids': [(6, 0, hol_ids)],
}, context=context)
act_model, act_id = self.pool['ir.model.data'].get_object_reference(
cr, uid, 'hr_holidays_usability', 'hr_holidays_post_action')
assert act_model == 'ir.actions.act_window', 'Wrong model'
action = self.pool[act_model].read(
cr, uid, act_id, context=context)
action['res_id'] = ids[0]
return action
def run(self, cr, uid, ids, context=None):
assert len(ids) == 1, 'Only 1 ID'
wiz = self.browse(cr, uid, ids[0], context=context)
today = fields.date.context_today(self, cr, uid, context=context)
if not wiz.holidays_to_post_ids:
raise orm.except_orm(
_('Error:'),
_('No for the number of days.'))
hol_ids = self.read(
cr, uid, ids[0], context=context)['holidays_to_post_ids']
self.pool['hr.holidays'].write(
cr, uid, hol_ids,
{'posted_date': today}, context=context)
# On v8, return a graph view !
act_model, act_id = self.pool['ir.model.data'].get_object_reference(
cr, uid, 'hr_holidays', 'open_ask_holidays')
assert act_model == 'ir.actions.act_window', 'Wrong model'
action = self.pool[act_model].read(
cr, uid, act_id, context=context)
action.update({
'target': 'current',
'domain': [('id', 'in', hol_ids)],
'nodestroy': True,
'context': {'group_by': ['employee_id', 'holiday_status_id']},
})
return action

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="hr_holidays_post_form" model="ir.ui.view">
<field name="name">hr_holidays_post_form</field>
<field name="model">hr.holidays.post</field>
<field name="arch" type="xml">
<form string="Post Leaves" version="7.0">
<group name="main" string="Leave Requests to Post">
<field name="state" invisible="1"/>
<field name="before_date" states="draft"/>
<field name="holidays_to_post_ids" nolabel="1"
context="{'tree_view_ref': 'hr_holidays.view_holiday'}"
states="done"/>
</group>
<footer>
<button name="select_date" type="object" string="Get Holiday Requests"
class="oe_highlight" states="draft"/>
<button name="run" type="object" string="Post"
class="oe_highlight" states="done"/>
<button special="cancel" string="Cancel" class="oe_link"/>
</footer>
</form>
</field>
</record>
<record id="hr_holidays_post_action" model="ir.actions.act_window">
<field name="name">Post Leave Requests</field>
<field name="res_model">hr.holidays.post</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem id="hr_holidays_post_menu"
action="hr_holidays_post_action"
parent="hr_holidays.menu_open_ask_holidays"
groups="base.group_hr_user"/>
</data>
</openerp>