2011-04-25 12:30:44 +00:00
|
|
|
# -*- 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/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2011-05-02 12:18:22 +00:00
|
|
|
import time
|
|
|
|
from datetime import datetime
|
|
|
|
from dateutil import relativedelta
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields, osv
|
|
|
|
from openerp.tools.translate import _
|
2011-04-25 12:30:44 +00:00
|
|
|
|
2011-05-03 12:38:07 +00:00
|
|
|
class hr_payslip_employees(osv.osv_memory):
|
2011-04-25 12:30:44 +00:00
|
|
|
|
2011-05-03 12:38:07 +00:00
|
|
|
_name ='hr.payslip.employees'
|
|
|
|
_description = 'Generate payslips for all selected employees'
|
2011-04-25 12:30:44 +00:00
|
|
|
_columns = {
|
2011-05-03 12:38:07 +00:00
|
|
|
'employee_ids': fields.many2many('hr.employee', 'hr_employee_group_rel', 'payslip_id', 'employee_id', 'Employees'),
|
2011-04-25 12:30:44 +00:00
|
|
|
}
|
2011-05-24 11:41:17 +00:00
|
|
|
|
2011-04-25 12:30:44 +00:00
|
|
|
def compute_sheet(self, cr, uid, ids, context=None):
|
|
|
|
emp_pool = self.pool.get('hr.employee')
|
|
|
|
slip_pool = self.pool.get('hr.payslip')
|
2011-05-18 05:01:48 +00:00
|
|
|
run_pool = self.pool.get('hr.payslip.run')
|
2011-04-26 11:37:09 +00:00
|
|
|
slip_ids = []
|
2011-04-25 12:30:44 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
data = self.read(cr, uid, ids, context=context)[0]
|
2011-06-09 10:07:43 +00:00
|
|
|
run_data = {}
|
2011-05-26 08:39:01 +00:00
|
|
|
if context and context.get('active_id', False):
|
|
|
|
run_data = run_pool.read(cr, uid, context['active_id'], ['date_start', 'date_end', 'credit_note'])
|
2011-06-09 10:07:43 +00:00
|
|
|
from_date = run_data.get('date_start', False)
|
|
|
|
to_date = run_data.get('date_end', False)
|
|
|
|
credit_note = run_data.get('credit_note', False)
|
2011-05-02 12:18:22 +00:00
|
|
|
if not data['employee_ids']:
|
2013-06-07 11:38:29 +00:00
|
|
|
raise osv.except_osv(_("Warning!"), _("You must select employee(s) to generate payslip(s)."))
|
2011-05-02 12:18:22 +00:00
|
|
|
for emp in emp_pool.browse(cr, uid, data['employee_ids'], context=context):
|
2011-05-18 05:01:48 +00:00
|
|
|
slip_data = slip_pool.onchange_employee_id(cr, uid, [], from_date, to_date, emp.id, contract_id=False, context=context)
|
2011-04-26 11:37:09 +00:00
|
|
|
res = {
|
|
|
|
'employee_id': emp.id,
|
2011-05-02 12:18:22 +00:00
|
|
|
'name': slip_data['value'].get('name', False),
|
|
|
|
'struct_id': slip_data['value'].get('struct_id', False),
|
|
|
|
'contract_id': slip_data['value'].get('contract_id', False),
|
2011-05-03 13:17:50 +00:00
|
|
|
'payslip_run_id': context.get('active_id', False),
|
2011-05-12 04:59:02 +00:00
|
|
|
'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids', False)],
|
2011-05-24 11:41:17 +00:00
|
|
|
'worked_days_line_ids': [(0, 0, x) for x in slip_data['value'].get('worked_days_line_ids', False)],
|
|
|
|
'date_from': from_date,
|
|
|
|
'date_to': to_date,
|
2011-05-26 08:39:01 +00:00
|
|
|
'credit_note': credit_note,
|
2011-04-26 11:37:09 +00:00
|
|
|
}
|
2011-05-11 09:10:09 +00:00
|
|
|
slip_ids.append(slip_pool.create(cr, uid, res, context=context))
|
2011-04-26 10:26:56 +00:00
|
|
|
slip_pool.compute_sheet(cr, uid, slip_ids, context=context)
|
2011-04-25 12:30:44 +00:00
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
|
|
|
|
2011-05-03 12:38:07 +00:00
|
|
|
hr_payslip_employees()
|
2011-04-25 12:30:44 +00:00
|
|
|
|
2011-06-09 10:07:43 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|