[IMP] Add wizard to generate payslip by employee categories
bzr revid: psi@tinyerp.co.in-20110425123044-hxb20cq7iynw5ou7
This commit is contained in:
@@ -57,6 +57,7 @@ Generic Payroll system.
|
||||
'security/ir.model.access.csv',
|
||||
'wizard/hr_payroll_employees_detail.xml',
|
||||
'wizard/hr_payroll_year_salary.xml',
|
||||
'wizard/hr_payroll_payslips_by_category.xml',
|
||||
],
|
||||
'test': [
|
||||
# 'test/payslip.yml',
|
||||
|
||||
@@ -204,6 +204,15 @@ class one2many_mod2(fields.one2many):
|
||||
res[r[self._fields_id]].append( r['id'] )
|
||||
return res
|
||||
|
||||
class hr_payslip_groups(osv.osv):
|
||||
|
||||
_name = 'hr.payslip.groups'
|
||||
_columns = {
|
||||
'name':fields.char('Name', size=256, required=True),
|
||||
'slip_ids':fields.one2many('hr.payslip', 'payslip_group_id', 'Payslips', required=False, readonly=True),
|
||||
}
|
||||
hr_payslip_groups()
|
||||
|
||||
class hr_payslip(osv.osv):
|
||||
'''
|
||||
Pay Slip
|
||||
@@ -215,13 +224,14 @@ class hr_payslip(osv.osv):
|
||||
def _get_lines_salary_head(self, cr, uid, ids, field_names, arg=None, context=None):
|
||||
result = {}
|
||||
if not ids: return result
|
||||
for id in ids:
|
||||
result.setdefault(id, [])
|
||||
cr.execute('''SELECT pl.slip_id, pl.id FROM hr_payslip_line AS pl \
|
||||
LEFT JOIN hr_salary_head AS sh on (pl.category_id = sh.id) \
|
||||
WHERE pl.slip_id in %s \
|
||||
GROUP BY pl.slip_id, sh.sequence, pl.sequence, pl.id ORDER BY sh.sequence, pl.sequence''',(tuple(ids),))
|
||||
res = cr.fetchall()
|
||||
for r in res:
|
||||
result.setdefault(r[0], [])
|
||||
result[r[0]].append(r[1])
|
||||
return result
|
||||
|
||||
@@ -255,6 +265,7 @@ class hr_payslip(osv.osv):
|
||||
'contract_id': fields.many2one('hr.contract', 'Contract', required=False, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'details_by_salary_head': fields.function(_get_lines_salary_head, method=True, type='one2many', relation='hr.payslip.line', string='Details by Salary Head'),
|
||||
'credit_note': fields.boolean('Credit Note', help="Indicates this payslip has a refund of another"),
|
||||
'payslip_group_id': fields.many2one('hr.payslip.groups', 'Group', readonly=True, states={'draft': [('readonly', False)]}),
|
||||
}
|
||||
_defaults = {
|
||||
'date_from': lambda *a: time.strftime('%Y-%m-01'),
|
||||
|
||||
@@ -188,8 +188,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Payslip Lines">
|
||||
<group col="8" colspan="4">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="slip_id"/>
|
||||
<field name="amount_select"/>
|
||||
</group>
|
||||
@@ -211,7 +211,7 @@
|
||||
<field name="model">hr.payslip</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree colors="blue:state in ('confirm','hr_check','accont_check');black:state in ('new');gray:state in('cancel')" string="Payslip">
|
||||
<tree colors="blue:state in ('confirm','hr_check','accont_check');black:state in ('new');gray:state in('cancel')" string="Payslips">
|
||||
<field name="number"/>
|
||||
<field name="employee_id"/>
|
||||
<field name="name"/>
|
||||
@@ -278,7 +278,7 @@
|
||||
</field>
|
||||
</page>
|
||||
<!-- TODO: put me back -->
|
||||
<page string="Details By Salary Head">
|
||||
<page string="Details By Salary Head">
|
||||
<field name="details_by_salary_head" context="{'group_by':'category_id'}" domain="[('appears_on_payslip', '=', True)]" nolabel="1">
|
||||
<tree string="Payslip Lines">
|
||||
<field name="category_id"/>
|
||||
@@ -549,14 +549,14 @@
|
||||
<field name="amount_select"/><newline/>
|
||||
<field name="amount_fix" attrs="{'invisible':[('amount_select','<>','fix')], 'required':[('amount_select','=','fix')]}"/>
|
||||
<field colspan="4" name="amount_python_compute" attrs="{'invisible':[('amount_select','<>','code')], 'required':[('amount_select','=','code')]}"/>
|
||||
<field name="amount_percentage_base" attrs="{'invisible':[('amount_select','<>','percentage')], 'required': [('amount_select','=','percentage')]}"/>
|
||||
<field name="amount_percentage_base" attrs="{'invisible':[('amount_select','<>','percentage')], 'required': [('amount_select','=','percentage')]}"/>
|
||||
<field name="amount_percentage" attrs="{'invisible':[('amount_select','<>','percentage')], 'required':[('amount_select','=','percentage')]}"/>
|
||||
<separator colspan="4" string="Company contribution"/>
|
||||
<field name="register_id"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Child Rules">
|
||||
<field name="parent_rule_id"/>
|
||||
<field name="parent_rule_id"/>
|
||||
<separator colspan="4" string="Children definition"/>
|
||||
<field colspan="4" name="child_ids" nolabel="1"/>
|
||||
</page>
|
||||
@@ -601,6 +601,38 @@
|
||||
|
||||
<act_window domain="[('slip_id', '=', active_id)]" id="act_payslip_lines" name="Payslip Lines" res_model="hr.payslip.line" src_model="hr.payslip"/>
|
||||
|
||||
<record id="hr_payslip_category_tree" model="ir.ui.view">
|
||||
<field name="name">hr.payslip.category.tree</field>
|
||||
<field name="model">hr.payslip.groups</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Payslip Groups">
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_payslip_category_form" model="ir.ui.view">
|
||||
<field name="name">hr.payslip.category.form</field>
|
||||
<field name="model">hr.payslip.groups</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Payslip by Category">
|
||||
<group colspan="4">
|
||||
<field name="name"/>
|
||||
</group>
|
||||
<field name="slip_ids" colspan="4" nolabel="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_hr_payslip_category_tree" model="ir.actions.act_window">
|
||||
<field name="name">Payslips by Category</field>
|
||||
<field name="res_model">hr.payslip.groups</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="hr_payslip_category_tree"/>
|
||||
</record>
|
||||
<menuitem action="action_hr_payslip_category_tree" id="menu_hr_payslip_category" parent="menu_hr_root_payroll"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# d$
|
||||
#
|
||||
@@ -24,5 +24,5 @@
|
||||
import hr_payroll_employees_detail
|
||||
#import hr_payroll_create_analytic
|
||||
import hr_payroll_year_salary
|
||||
|
||||
import hr_payroll_payslips_by_category
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 osv import fields, osv
|
||||
import netsvc
|
||||
|
||||
class hr_payroll_payslip_groups(osv.osv_memory):
|
||||
|
||||
_name ='hr.payroll.payslip.groups'
|
||||
_columns = {
|
||||
'employee_category': fields.many2one('hr.employee.category', 'Employee Category', required=True),
|
||||
}
|
||||
|
||||
def compute_sheet(self, cr, uid, ids, context=None):
|
||||
emp_pool = self.pool.get('hr.employee')
|
||||
slip_pool = self.pool.get('hr.payslip')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
if context is None:
|
||||
context = {}
|
||||
data = self.read(cr, uid, ids, context=context)[0]
|
||||
cr.execute('SELECT DISTINCT emp_id FROM employee_category_rel WHERE category_id = %s', (data['employee_category'][0], ))
|
||||
emp_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
|
||||
for emp in emp_pool.browse(cr, uid, emp_ids, context=context):
|
||||
old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id)], context=context)
|
||||
if old_slips:
|
||||
slip_pool.write(cr, uid, old_slips, {'payslip_group_id': context.get('active_id', False)}, context=context)
|
||||
for sid in old_slips:
|
||||
wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr)
|
||||
else:
|
||||
res = {
|
||||
'employee_id': emp.id,
|
||||
'payslip_group_id': context.get('active_id', False),
|
||||
}
|
||||
slip_id = slip_pool.create(cr, uid, res, context=context)
|
||||
wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
hr_payroll_payslip_groups()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_hr_payslip_by_category" model="ir.ui.view">
|
||||
<field name="name">hr_payroll_payslip_category</field>
|
||||
<field name="model">hr.payroll.payslip.groups</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Employee Category">
|
||||
<group colspan="4" >
|
||||
<separator string="Select Employee Category" colspan="4"/>
|
||||
<field name="employee_category"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="6">
|
||||
<label string ="" colspan="2"/>
|
||||
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
|
||||
<button icon="terp-gtk-go-back-rtl" string="Generate Payslip" name="compute_sheet" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_hr_payslip_by_category" model="ir.actions.act_window">
|
||||
<field name="name">Generate Payslips by Category</field>
|
||||
<field name="res_model">hr.payroll.payslip.groups</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_hr_payslip_by_category"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="action_idea_post_vote_values" model="ir.values">
|
||||
<field name="model_id" ref="model_hr_payslip_groups" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Generate Payslips by Category</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_hr_payslip_by_category'))"/>
|
||||
<field name="key">action</field>
|
||||
<field name="model">hr.payslip.groups</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user