From da3745b2d6eb8ebfcd9f1b3ec4071b80903c844f Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 9 Mar 2011 19:00:27 +0530 Subject: [PATCH 1/2] [IMP] hr_payroll: Get payslip_line for leaves bzr revid: psi@tinyerp.co.in-20110309133027-2z1b6i3pvz0di3i9 --- addons/hr_payroll/hr_payroll.py | 79 +++++++++++++++------------------ 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 0a92fd1f40c..2c40a280fea 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -869,7 +869,7 @@ class hr_payslip(osv.osv): holiday_pool = self.pool.get('hr.holidays') sequence_obj = self.pool.get('ir.sequence') empolyee_obj = self.pool.get('hr.employee') - hr_all_ded_cate = self.pool.get('hr.allounce.deduction.categoty') + hr_salary_head = self.pool.get('hr.salary.head') resource_attendance_pool = self.pool.get('resource.calendar.attendance') if context is None: context = {} @@ -1007,6 +1007,7 @@ class hr_payslip(osv.osv): update['value']['line_ids'].append(vals) basic_before_leaves = update['value']['basic_amount'] + total_before_leaves = update['value']['total_pay'] working_day = 0 off_days = 0 dates = prev_bounds(ddate) @@ -1031,69 +1032,59 @@ class hr_payslip(osv.osv): leave_ids = self._get_leaves1(cr, uid, ddate, employee_id, context) total_leave = 0.0 paid_leave = 0.0 - h_ids = holiday_pool.browse(cr, uid, leave_ids, context=context) for hday in holiday_pool.browse(cr, uid, leave_ids, context=context): -# if not hday.holiday_status_id.code: -# raise osv.except_osv(_('Error !'), _('Please check configuration of %s, payroll head is missing') % (hday.holiday_status_id.name)) - slip_lines = hr_all_ded_cate.search(cr, uid, [('code','=',hday.holiday_status_id.code)], context=context) + if not hday.holiday_status_id.code: + raise osv.except_osv(_('Error !'), _('Please check configuration of %s, code is missing') % (hday.holiday_status_id.name)) + slip_lines = salary_rule_pool.search(cr, uid, [('code','=',hday.holiday_status_id.code)], context=context) head_sequence = 0 - if slip_lines: - head_sequence = hr_all_ded_cate.read(cr, uid, slip_lines, ['sequence'], context=context)[0]['sequence'] + if not slip_lines: + raise osv.except_osv(_('Error !'), _('Please check configuration of %s, Salary rule is missing') % (hday.holiday_status_id.name)) + salary_rule = salary_rule_pool.browse(cr, uid, slip_lines, context=context)[0] res = { - 'slip_id': hday.id, - 'name': hday.holiday_status_id.name + '-%s' % (hday.number_of_days), - 'code': hday.holiday_status_id.code, - 'amount_type': 'fix', - 'category_id': slip_lines and slip_lines[0], - 'sequence': head_sequence -# 'category_id': hday.holiday_status_id.head_id.id, -# 'sequence': hday.holiday_status_id.head_id.sequence + 'slip_id': salary_rule.id, + 'name': salary_rule.name + '-%s' % (hday.number_of_days), + 'code': salary_rule.code, + 'amount_type': salary_rule.amount_type, + 'category_id': salary_rule.category_id.id, + 'sequence': salary_rule.sequence } days = hday.number_of_days if hday.number_of_days < 0: days = hday.number_of_days * -1 total_leave += days -# if hday.holiday_status_id.type == 'paid': -# paid_leave += days -# continue -## res['name'] = hday.holiday_status_id.name + '-%s' % (days) -## res['amount'] = perday * days -## res['type'] = 'allowance' -## leave += days -## total += perday * days -# -# elif hday.holiday_status_id.type == 'halfpaid': -# paid_leave += (days / 2) -# res['name'] = hday.holiday_status_id.name + '-%s/2' % (days) -# res['amount'] = perday * (days/2) -# total += perday * (days/2) -# res['total'] = total -# leave += days / 2 -# res['type'] = 'deduction' -# else: - res['name'] = hday.holiday_status_id.name + '-%s' % (days) - res['amount'] = perday * days - res['type'] = 'deduction' + + base = line.computational_expression + try: + #Please have a look at the configuration guide. + amt = eval(base, obj) + except Exception, e: + raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e)) + if salary_rule.amount_type == 'per': + try: + value = salary_rule.amount * amt * days + except Exception, e: + raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e)) + elif salary_rule.amount_type == 'fix': + value = salary_rule.amount * days + res['amount'] = salary_rule.amount + res['type'] = salary_rule.type.id leave += days - total += perday * days - res['total'] = total -# slip_line_pool.create(cr, uid, res, context=context) + total += value + res['total'] = value update['value']['line_ids'].append(res) -# holiday_pool.write(cr, uid, leave_ids, {'payslip_id': ids and ids[0] or False}, context=context) - basic = basic - total + basic = basic + total # leaves = total - temp_dic = self.pool.get('hr.holidays').read(cr, uid, leave_ids, [], context=context) + temp_dic = holiday_pool.read(cr, uid, leave_ids, [], context=context) update['value'].update({ 'basic_amount': basic, 'basic_before_leaves': round(basic_before_leaves), -# 'total_pay': round(basic_before_leaves)+ allounce - (deduction + total), + 'total_pay': total_before_leaves + total, 'leaves': total, 'holiday_days': leave, 'worked_days': working_day - leave, 'working_days': working_day, # 'holiday_ids': temp_dic }) -# self.write(cr, uid, uid, update, context=context) return update hr_payslip() From 2dc26c64c188e971af670975c2ad118bf40bc643 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Thu, 10 Mar 2011 17:25:25 +0530 Subject: [PATCH 2/2] [IMP] fix the problem related to save the payslip record bzr revid: psi@tinyerp.co.in-20110310115525-hdmc23gxma25jbya --- addons/hr_payroll/hr_payroll.py | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 2c40a280fea..3e118949909 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -969,8 +969,7 @@ class hr_payslip(osv.osv): 'amount_type': line.amount_type, 'amount': line.amount, 'total': value, - 'slip_id': line.id, - 'employee_id': False, + 'employee_id': employee_id.id, # 'function_id': False, 'base': line.computational_expression } @@ -990,21 +989,20 @@ class hr_payslip(osv.osv): 'company_id': employee_id.company_id.id }) - for line in employee_id.line_ids: - vals = { - 'category_id': line.category_id.id, - 'name': line.name, - 'sequence': line.sequence, - 'type': line.type, - 'code': line.code, - 'amount_type': line.amount_type, - 'amount': line.amount, - 'slip_id': line.id, - 'employee_id': False, -# 'function_id': False, - 'base': base - } - update['value']['line_ids'].append(vals) +# for line in employee_id.line_ids: +# vals = { +# 'category_id': line.category_id.id, +# 'name': line.name, +# 'sequence': line.sequence, +# 'type': line.type.id, +# 'code': line.code, +# 'amount_type': line.amount_type, +# 'amount': line.amount, +# 'employee_id': employee_id.id, +## 'function_id': False, +# 'base': base +# } +# update['value']['line_ids'].append(vals) basic_before_leaves = update['value']['basic_amount'] total_before_leaves = update['value']['total_pay'] @@ -1040,20 +1038,21 @@ class hr_payslip(osv.osv): if not slip_lines: raise osv.except_osv(_('Error !'), _('Please check configuration of %s, Salary rule is missing') % (hday.holiday_status_id.name)) salary_rule = salary_rule_pool.browse(cr, uid, slip_lines, context=context)[0] + base = salary_rule.computational_expression res = { - 'slip_id': salary_rule.id, 'name': salary_rule.name + '-%s' % (hday.number_of_days), 'code': salary_rule.code, 'amount_type': salary_rule.amount_type, 'category_id': salary_rule.category_id.id, - 'sequence': salary_rule.sequence + 'sequence': salary_rule.sequence, + 'employee_id': employee_id.id, + 'base': base } days = hday.number_of_days if hday.number_of_days < 0: days = hday.number_of_days * -1 total_leave += days - base = line.computational_expression try: #Please have a look at the configuration guide. amt = eval(base, obj) @@ -1074,7 +1073,7 @@ class hr_payslip(osv.osv): update['value']['line_ids'].append(res) basic = basic + total # leaves = total - temp_dic = holiday_pool.read(cr, uid, leave_ids, [], context=context) +# temp_dic = holiday_pool.read(cr, uid, leave_ids, [], context=context) update['value'].update({ 'basic_amount': basic, 'basic_before_leaves': round(basic_before_leaves), @@ -1142,7 +1141,7 @@ class hr_payslip_line(osv.osv): ('code','Python Code'), ],'Amount Type', select=True, required=True), 'amount': fields.float('Amount / Percentage', digits=(16, 4)), - 'total': fields.float('Sub Total', readonly=True, digits_compute=dp.get_precision('Account')), + 'total': fields.float('Sub Total', digits_compute=dp.get_precision('Account')), 'company_contrib': fields.float('Company Contribution', readonly=True, digits=(16, 4)), 'sequence': fields.integer('Sequence'), 'note':fields.text('Description'),