diff --git a/addons/hr_payroll/__openerp__.py b/addons/hr_payroll/__openerp__.py index 87fe437a1db..822573db480 100644 --- a/addons/hr_payroll/__openerp__.py +++ b/addons/hr_payroll/__openerp__.py @@ -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', diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 6757b57c417..55ec3d7995a 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -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'), diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index e1efc9d7f0c..e319b209011 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -188,8 +188,8 @@ - - + + @@ -211,7 +211,7 @@ hr.payslip tree - + @@ -278,7 +278,7 @@ - + @@ -549,14 +549,14 @@ - + - + @@ -601,6 +601,38 @@ + + hr.payslip.category.tree + hr.payslip.groups + tree + + + + + + + + + hr.payslip.category.form + hr.payslip.groups + form + +
+ + + + + +
+
+ + + Payslips by Category + hr.payslip.groups + form + + + diff --git a/addons/hr_payroll/wizard/__init__.py b/addons/hr_payroll/wizard/__init__.py index 2cf78e17b1c..fc8083099a5 100644 --- a/addons/hr_payroll/wizard/__init__.py +++ b/addons/hr_payroll/wizard/__init__.py @@ -1,7 +1,7 @@ #-*- coding:utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution +# OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). 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: \ No newline at end of file diff --git a/addons/hr_payroll/wizard/hr_payroll_payslips_by_category.py b/addons/hr_payroll/wizard/hr_payroll_payslips_by_category.py new file mode 100644 index 00000000000..9f8d9c010f9 --- /dev/null +++ b/addons/hr_payroll/wizard/hr_payroll_payslips_by_category.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +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: diff --git a/addons/hr_payroll/wizard/hr_payroll_payslips_by_category.xml b/addons/hr_payroll/wizard/hr_payroll_payslips_by_category.xml new file mode 100644 index 00000000000..394a894c024 --- /dev/null +++ b/addons/hr_payroll/wizard/hr_payroll_payslips_by_category.xml @@ -0,0 +1,45 @@ + + + + + + hr_payroll_payslip_category + hr.payroll.payslip.groups + form + +
+ + + + + + +