~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to hr_payroll/report/report_employees_detail.py

  • Committer: Mantavya Gajjar
  • Date: 2009-11-23 08:55:16 UTC
  • Revision ID: mga@tinyerp.com-20091123085516-opohxaj3tkacm3kw
[ADD]: a new module for hr management that help to manage salaried

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import time
 
2
import locale
 
3
import datetime
 
4
from report import report_sxw
 
5
import time
 
6
import pooler
 
7
import rml_parse
 
8
import mx.DateTime
 
9
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
 
10
 
 
11
class employees_salary_report(rml_parse.rml_parse):
 
12
    
 
13
    def __init__(self, cr, uid, name, context):
 
14
        super(employees_salary_report, self).__init__(cr, uid, name, context)
 
15
        self.localcontext.update({
 
16
            'time': time,
 
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,
 
27
        })
 
28
        
 
29
        self.mnths =[]
 
30
        self.allow_list =[]
 
31
        self.deduct_list = []
 
32
        self.other_list = []
 
33
        self.month_total_list =[]
 
34
        self.curr_fiscal_year_name=''
 
35
        self.period_ids = []
 
36
        self.total=0.00
 
37
    
 
38
    def get_periods(self,form):
 
39
        self.mnths =[]
 
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]
 
43
        
 
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])
 
47
        
 
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
 
51
        cm = fm
 
52
        cy = fy
 
53
 
 
54
#       Get name of the months from integer
 
55
        mnth_name = []
 
56
        for count in range(0,no_months):
 
57
            m = datetime.date(cy, cm, 1).strftime('%b')
 
58
            mnth_name.append(m)
 
59
            self.mnths.append(str(cm)+'-'+str(cy))     
 
60
            if cm == 12:
 
61
                cm = 0
 
62
                cy = ly
 
63
            cm = cm +1
 
64
        return [mnth_name]
 
65
 
 
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']
 
69
 
 
70
    def get_employee(self,form):
 
71
        result = []   
 
72
        periods = []    
 
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))
 
81
        return result
 
82
    
 
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]
 
85
        self.allow_list =[]
 
86
        self.deduct_list = []
 
87
        self.other_list = []
 
88
        allowance_cat_ids =[]
 
89
        deduction_cat_ids = []
 
90
        other_cat_ids =[]
 
91
        self.total = 0.00        
 
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')])
 
97
        #for Basic Salary
 
98
        res = []
 
99
        res = self.cal_monthly_amt(obj.id,None)
 
100
        if res[1]!=0.0:
 
101
            self.total += res[len(res)-1]
 
102
            self.allow_list.append(res)
 
103
        #for allowance
 
104
        if allowance_cat_ids:
 
105
            for allow in allowance_cat_ids:
 
106
                 res = []
 
107
                 res = self.cal_monthly_amt(obj.id,allow)
 
108
                 if res[1]!=0.0:
 
109
                     self.allow_list.append(res)
 
110
                     self.total += res[len(res)-1]
 
111
        #for Deduction
 
112
        if deduction_cat_ids:
 
113
            for deduct in deduction_cat_ids:
 
114
                 res = []
 
115
                 res = self.cal_monthly_amt(obj.id,deduct)
 
116
                 if res[1]!=0.0:
 
117
                     self.deduct_list.append(res)
 
118
                     self.total -= res[len(res)-1]
 
119
        #for Other
 
120
        if other_cat_ids:
 
121
            for other in other_cat_ids:
 
122
                 res = []
 
123
                 res = self.cal_monthly_amt(obj.id,other)
 
124
                 if res[1]!=0.0:
 
125
                     self.other_list.append(res)
 
126
        return None
 
127
    
 
128
    def cal_monthly_amt(self,emp_id,category):
 
129
        tot = 0.0
 
130
        cnt = 1
 
131
        result = []
 
132
        if not category:
 
133
            result.append('Basic Salary')
 
134
        else:
 
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'])
 
137
            
 
138
        for mnth in self.mnths:
 
139
            if len(mnth) != 7:
 
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()
 
144
            if payslip_id:
 
145
                payslip_obj = self.pool.get('hr.payslip').browse(self.cr, self.uid, payslip_id['id'])
 
146
                if not category:
 
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
 
150
                else:
 
151
                    for line in payslip_obj.line_ids:
 
152
                        if line.category_id.id == category:
 
153
                            tot += line.total
 
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
 
159
            else:
 
160
                result.append(0.00)
 
161
            cnt = cnt + 1  
 
162
        cnt = 1
 
163
        result.append(tot)
 
164
        return result
 
165
 
 
166
    def get_allow(self):
 
167
        return self.allow_list
 
168
 
 
169
    def get_deduct(self):
 
170
        return self.deduct_list
 
171
    
 
172
    def get_other(self):
 
173
        return self.other_list
 
174
    
 
175
    def get_total(self):
 
176
        return self.total
 
177
    
 
178
    def get_monthly_total(self):
 
179
        return self.month_total_list
 
180
    
 
181
report_sxw.report_sxw('report.employees.salary', 'hr.payslip', 'hr_payroll/report/report_employees_detail.rml', parser=employees_salary_report)
 
182
       
 
183
       
 
184