[IMP] wizard will work for employees instead of employee categories

bzr revid: psi@tinyerp.co.in-20110502121822-2xw9r1yilxoovr2o
This commit is contained in:
psi (Open ERP) 2011-05-02 17:48:22 +05:30
parent 588093d070
commit 978b756760
5 changed files with 44 additions and 22 deletions

View File

@ -413,7 +413,7 @@ class hr_payslip(osv.osv):
for payslip in self.browse(cr, uid, ids, context=context):
#delete old payslip lines
old_slipline_ids = slip_line_pool.search(cr, uid, [('slip_id', '=', payslip.id)], context=context)
old_slipline_ids
# old_slipline_ids
if old_slipline_ids:
slip_line_pool.unlink(cr, uid, old_slipline_ids, context=context)
if payslip.contract_id:
@ -565,27 +565,28 @@ class hr_payslip(osv.osv):
#defaults
res = {'value':{
'line_ids':[],
'input_line_ids': [],
#'details_by_salary_head':[], TODO put me back
'name':'',
'contract_id': False,
'struct_id': False,
}
}
}
if not employee_id:
return res
ttyme = datetime.fromtimestamp(time.mktime(time.strptime(date_from, "%Y-%m-%d")))
employee_id = empolyee_obj.browse(cr, uid, employee_id, context=context)
res['value'].update({
'name': _('Salary Slip of %s for %s') % (employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
'company_id': employee_id.company_id.id
})
'name': _('Salary Slip of %s for %s') % (employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
'company_id': employee_id.company_id.id
})
if not context.get('contract', False):
#fill with the first contract of the employee
contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context)
res['value'].update({
'struct_id': contract_ids and contract_obj.read(cr, uid, contract_ids[0], ['struct_id'], context=context)['struct_id'][0] or False,
'contract_id': contract_ids and contract_ids[0] or False,
'struct_id': contract_ids and contract_obj.read(cr, uid, contract_ids[0], ['struct_id'], context=context)['struct_id'][0] or False,
'contract_id': contract_ids and contract_ids[0] or False,
})
else:
if contract_id:
@ -593,7 +594,10 @@ class hr_payslip(osv.osv):
contract_ids = [contract_id]
#fill the structure with the one on the selected contract
contract_record = contract_obj.browse(cr, uid, contract_id, context=context)
res['value'].update({'struct_id': contract_record.struct_id.id, 'contract_id': contract_id})
res['value'].update({
'struct_id': contract_record.struct_id.id,
'contract_id': contract_id
})
else:
#if we don't give the contract, then the input to fill should be for all current contracts of the employee
contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context)
@ -604,7 +608,7 @@ class hr_payslip(osv.osv):
input_line_ids = self.get_input_lines(cr, uid, contract_ids, date_from, date_to, context=context)
res['value'].update({
'input_line_ids': input_line_ids,
})
})
return res
def onchange_contract_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None):

View File

@ -306,6 +306,7 @@
<separator colspan="4" string="Other Information"/>
<group col="5" colspan="2">
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="payslip_group_id"/>
<field name="paid" readonly="1"/>
</group>
<newline/>
@ -629,16 +630,21 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Payslips Group">
<group colspan="4">
<group col="6" colspan="6">
<field name="name"/>
</group>
<field name="slip_ids" colspan="4" nolabel="1"/>
<notebook colspan="6">
<page string="Payslips">
<field name="slip_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
<button name="%(action_hr_payslip_by_category)d" type="action" icon="terp-stock_effects-object-colorize" string="Generate Payslips" />
</form>
</field>
</record>
<record id="action_hr_payslip_category_tree" model="ir.actions.act_window">
<field name="name">Payslip Groups</field>
<field name="name">Payslip Run</field>
<field name="res_model">hr.payslip.groups</field>
<field name="view_type">form</field>
<field name="view_id" ref="hr_payslip_category_tree"/>

View File

@ -10,3 +10,4 @@
"access_hr_payroll_structure_manager","hr.payroll.structure.manager","model_hr_payroll_structure","base.group_hr_manager",1,1,1,1
"access_hr_payslip_input ","hr.payslip.input","model_hr_payslip_input","base.group_hr_manager",1,1,1,1
"access_hr_salary_rule","hr.salary.rule","model_hr_salary_rule","base.group_hr_manager",1,1,1,1
"access_hr_payslip_groups","hr.payslip.groups","model_hr_payslip_groups","base.group_hr_manager",1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
10 access_hr_payroll_structure_manager hr.payroll.structure.manager model_hr_payroll_structure base.group_hr_manager 1 1 1 1
11 access_hr_payslip_input hr.payslip.input model_hr_payslip_input base.group_hr_manager 1 1 1 1
12 access_hr_salary_rule hr.salary.rule model_hr_salary_rule base.group_hr_manager 1 1 1 1
13 access_hr_payslip_groups hr.payslip.groups model_hr_payslip_groups base.group_hr_manager 1 1 1 1

View File

@ -19,6 +19,10 @@
#
##############################################################################
import time
from datetime import datetime
from dateutil import relativedelta
from osv import fields, osv
from tools.translate import _
@ -27,26 +31,33 @@ class hr_payslip_category(osv.osv_memory):
_name ='hr.payslip.category'
_description = 'Generate payslips for all employees within given category'
_columns = {
'category_id': fields.many2one('hr.employee.category', 'Employee Category', required=True),
'employee_ids': fields.many2many('hr.employee', 'hr_employee_group_rel', 'struct_id', 'employee_id', 'Employees'),
}
def compute_sheet(self, cr, uid, ids, context=None):
emp_pool = self.pool.get('hr.employee')
slip_pool = self.pool.get('hr.payslip')
input_line_pool = self.pool.get('hr.payslip.input')
slip_ids = []
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['category_id'][0], ))
emp_ids = [x[0] for x in cr.fetchall()]
if not emp_ids:
raise osv.except_osv(_("Warning !"), _("No employee(s) found for '%s' category!") % (data['category_id'][1]))
for emp in emp_pool.browse(cr, uid, emp_ids, context=context):
if not data['employee_ids']:
raise osv.except_osv(_("Warning !"), _("You must select employees to generate payslip"))
for emp in emp_pool.browse(cr, uid, data['employee_ids'], context=context):
slip_data = slip_pool.onchange_employee_id(cr, uid, [], time.strftime('%Y-%m-01'), str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10], emp.id, contract_id=False, context=context)
res = {
'employee_id': emp.id,
'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),
'payslip_group_id': context.get('active_id', False),
}
slip_ids.append(slip_pool.create(cr, uid, res, context=context))
slip_id = slip_pool.create(cr, uid, res, context=context)
for input in slip_data['value']['input_line_ids']:
input.update({'payslip_id': slip_id})
input_line_pool.create(cr, uid, input, context=context)
slip_ids.append(slip_id)
slip_pool.compute_sheet(cr, uid, slip_ids, context=context)
return {'type': 'ir.actions.act_window_close'}

View File

@ -12,7 +12,7 @@
<separator string="Payslips by employee category" colspan="4"/>
<label colspan="4" nolabel="1" string="This wizard will generate payslips for all employee(s), who belogs to selected category" />
<newline/>
<field name="category_id"/>
<field name="employee_ids" nolabel="1"/>
</group>
<separator string="" colspan="4" />
<group colspan="4" col="6">
@ -33,14 +33,14 @@
<field name="target">new</field>
</record>
<record id="action_idea_post_vote_values" model="ir.values">
<!-- <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</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="model">hr.payslip.groups</field>
</record>
</record> -->
</data>
</openerp>