4
from report import report_sxw
9
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
11
class employees_salary_report(rml_parse.rml_parse):
13
def __init__(self, cr, uid, name, context):
14
super(employees_salary_report, self).__init__(cr, uid, name, context)
15
self.localcontext.update({
17
'get_employee' : self.get_employee,
18
'get_employee_detail' : self.get_employee_detail,
19
'cal_monthly_amt':self.cal_monthly_amt,
20
'get_periods' : self.get_periods,
21
'get_fiscalyear' : self.get_fiscalyear,
22
'get_total' : self.get_total,
23
'get_allow':self.get_allow,
24
'get_deduct':self.get_deduct,
25
'get_other':self.get_other,
26
'get_monthly_total':self.get_monthly_total,
33
self.month_total_list =[]
34
self.curr_fiscal_year_name=''
38
def get_periods(self,form):
40
fiscalyear = pooler.get_pool(self.cr.dbname).get('account.fiscalyear')
41
curr_fiscalyear_id = form['fiscalyear_id']
42
curr_fiscalyear = fiscalyear.read(self.cr,self.uid,[form['fiscalyear_id']],['date_start','date_stop'])[0]
44
# Get start year-month-date and end year-month-date
45
fy = int(curr_fiscalyear['date_start'][0:4])
46
ly = int(curr_fiscalyear['date_stop'][0:4])
48
fm = int(curr_fiscalyear['date_start'][5:7])
49
lm = int(curr_fiscalyear['date_stop'][5:7])
50
no_months = (ly-fy)*12+lm-fm + 1
54
# Get name of the months from integer
56
for count in range(0,no_months):
57
m = datetime.date(cy, cm, 1).strftime('%b')
59
self.mnths.append(str(cm)+'-'+str(cy))
66
def get_fiscalyear(self,fiscalyear_id):
67
fiscalyear_obj = pooler.get_pool(self.cr.dbname).get('account.fiscalyear')
68
return fiscalyear_obj.read(self.cr,self.uid,[fiscalyear_id],['name'])[0]['name']
70
def get_employee(self,form):
73
emp = pooler.get_pool(self.cr.dbname).get('hr.employee')
74
emp_ids = form['employee_ids'][0][2]
75
result = emp.browse(self.cr,self.uid, emp_ids)
76
fiscalyear_obj = pooler.get_pool(self.cr.dbname).get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear_id'])
77
period_ids_l = fiscalyear_obj.period_ids
78
for period in period_ids_l:
79
periods.append(period.id)
80
self.period_ids = ','.join(map(str, periods))
83
def get_employee_detail(self,obj):
84
self.month_total_list =['Net Total (Allowances with Basic - Deductions)',0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00]
89
deduction_cat_ids = []
92
payment_category = self.pool.get('hr.allounce.deduction.categoty')
93
payslip = self.pool.get('hr.payslip')
94
allowance_cat_ids = payment_category.search( self.cr, self.uid, [('type','=','allow')])
95
deduction_cat_ids = payment_category.search( self.cr, self.uid, [('type','=','deduct')])
96
other_cat_ids = payment_category.search( self.cr, self.uid, [('type','=','other')])
99
res = self.cal_monthly_amt(obj.id,None)
101
self.total += res[len(res)-1]
102
self.allow_list.append(res)
104
if allowance_cat_ids:
105
for allow in allowance_cat_ids:
107
res = self.cal_monthly_amt(obj.id,allow)
109
self.allow_list.append(res)
110
self.total += res[len(res)-1]
112
if deduction_cat_ids:
113
for deduct in deduction_cat_ids:
115
res = self.cal_monthly_amt(obj.id,deduct)
117
self.deduct_list.append(res)
118
self.total -= res[len(res)-1]
121
for other in other_cat_ids:
123
res = self.cal_monthly_amt(obj.id,other)
125
self.other_list.append(res)
128
def cal_monthly_amt(self,emp_id,category):
133
result.append('Basic Salary')
135
category_name = self.pool.get('hr.allounce.deduction.categoty').read(self.cr, self.uid, [category],['name','type'])[0]
136
result.append(category_name['name'])
138
for mnth in self.mnths:
140
mnth = '0' + str(mnth)
141
query = "select id from hr_payslip where employee_id = "+str(emp_id)+" and to_char(date,'mm-yyyy') like '%"+mnth+"%' and state = 'done' and period_id in "+"("+ self.period_ids +")" +""
142
self.cr.execute(query)
143
payslip_id = self.cr.dictfetchone()
145
payslip_obj = self.pool.get('hr.payslip').browse(self.cr, self.uid, payslip_id['id'])
147
tot += payslip_obj.basic
148
result.append(payslip_obj.basic)
149
self.month_total_list[cnt] = self.month_total_list[cnt] + payslip_obj.basic
151
for line in payslip_obj.line_ids:
152
if line.category_id.id == category:
154
result.append(line.total)
155
if category_name['type'] == 'allow':
156
self.month_total_list[cnt] = self.month_total_list[cnt] + line.total
157
if category_name['type'] == 'deduct':
158
self.month_total_list[cnt] = self.month_total_list[cnt] - line.total
167
return self.allow_list
169
def get_deduct(self):
170
return self.deduct_list
173
return self.other_list
178
def get_monthly_total(self):
179
return self.month_total_list
181
report_sxw.report_sxw('report.employees.salary', 'hr.payslip', 'hr_payroll/report/report_employees_detail.rml', parser=employees_salary_report)