Introduce new wizard and counters
This commit is contained in:
2
hr_holidays_usability/report/__init__.py
Normal file
2
hr_holidays_usability/report/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
from . import hr_holidays_employee_counter
|
||||
71
hr_holidays_usability/report/hr_holidays_employee_counter.py
Normal file
71
hr_holidays_usability/report/hr_holidays_employee_counter.py
Normal 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
|
||||
)
|
||||
""")
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user