diff --git a/addons/hr_contract/hr_contract_view.xml b/addons/hr_contract/hr_contract_view.xml index 0f0e2e223d6..205a8842748 100644 --- a/addons/hr_contract/hr_contract_view.xml +++ b/addons/hr_contract/hr_contract_view.xml @@ -356,11 +356,11 @@ - diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index fd85d272b78..c846d8f5cf8 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -377,7 +377,7 @@ class hr_payslip(osv.osv): deduct = 0.0 others = 0.0 tot_amount = 0.0 - + contract = rs.employee_id.contract_id obj = {'basic': contract.wage} if not contract.struct_id: @@ -407,7 +407,9 @@ class hr_payslip(osv.osv): allow += amount others -= contrib amount += contrib + tot_amount += amount + salary_rule_pool.write(cr, uid, [line.id], {'total': amount}, context=context) record = { 'allounce': allow, @@ -874,7 +876,8 @@ 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 = {} @@ -917,8 +920,10 @@ class hr_payslip(osv.osv): return update contract = employee_id.contract_id + sal_structure = [] function = contract.struct_id.id + sal_structure.append(function) if contract.struct_id.parent_id: sal_structure.append(contract.struct_id.parent_id.id) @@ -950,6 +955,7 @@ class hr_payslip(osv.osv): cd = line.code.lower() obj[cd] = line.amount or 0.0 + for line in rules: if line.category_id.code in ad: continue @@ -986,7 +992,7 @@ class hr_payslip(osv.osv): value = line.amount * amt except Exception, e: raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e)) - + elif line.amount_type == 'fix': if line.condition_range_min or line.condition_range_max: if ((line.amount < line.condition_range_min) or (line.amount > line.condition_range_max)): @@ -1008,8 +1014,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 } @@ -1019,6 +1024,7 @@ class hr_payslip(osv.osv): update['value']['line_ids'].append(vals) else: update['value']['line_ids'].append(vals) + basic = contract.wage number = sequence_obj.get(cr, uid, 'salary.slip') update['value'].update({ @@ -1032,24 +1038,25 @@ class hr_payslip(osv.osv): 'contract_id': contract.id, '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'] + working_day = 0 off_days = 0 dates = prev_bounds(ddate) @@ -1074,69 +1081,63 @@ 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) +# 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] + base = salary_rule.computational_expression + 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 + '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, + '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 -# 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' + 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() @@ -1194,7 +1195,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'),