[CLEAN] Set Withespaces to PEP8 format
[odoo/odoo.git] / addons / hr_attendance / report / attendance_errors.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22
23 import time
24 from report import report_sxw
25 import pooler
26 import datetime
27
28 class attendance_print(report_sxw.rml_parse):
29     def __init__(self, cr, uid, name, context):
30         super(attendance_print, self).__init__(cr, uid, name, context=context)
31         self.localcontext.update({
32             'time': time,
33             'lst': self._lst,
34             'total': self._lst_total,
35             'get_employees':self._get_employees,
36         })
37
38     def _get_employees(self, emp_ids):
39         emp_obj_list = self.pool.get('hr.employee').browse(self.cr, self.uid, emp_ids)
40         return emp_obj_list
41
42 #    def _sign(self, dt):
43 #        if abs(dt.days) > 1:
44 #            format = '%d day'+(((abs(dt.days)>=2) and 's') or '')+' %H:%M:%S'
45 #        else:
46 #            format = '%H:%M:%S'
47 #        if dt.seconds<0:
48 #            return dt.strftime('- '+format)
49 #        else:
50 #            return dt.strftime(format)
51
52     def _lst(self, employee_id, dt_from, dt_to, max, *args):
53         self.cr.execute("select name as date, create_date, action, create_date-name as delay from hr_attendance where employee_id=%s and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action in (%s,%s) order by name", (employee_id, dt_to, dt_from, 'sign_in', 'sign_out'))
54         res = self.cr.dictfetchall()
55         for r in res:
56             if r['action'] == 'sign_out':
57                 r['delay'] = -r['delay']
58             temp = r['delay'].seconds
59
60 #            r['delay'] = self._sign(r['delay'])
61             r['delay'] = str(r['delay']).split('.')[0]
62             if abs(temp) < max * 60:
63                 r['delay2'] = r['delay']
64             else:
65                 r['delay2'] = '/'
66         return res
67
68     def _lst_total(self, employee_id, dt_from, dt_to, max, *args):
69         self.cr.execute("select name as date, create_date, action, create_date-name as delay from hr_attendance where employee_id=%s and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action in (%s,%s) order by name", (employee_id, dt_to, dt_from, 'sign_in', 'sign_out'))
70         res = self.cr.dictfetchall()
71         if not res:
72             return ('/', '/')
73         total2 = datetime.timedelta(seconds=0, minutes=0, hours=0)
74         total = datetime.timedelta(seconds=0, minutes=0, hours=0)
75         for r in res:
76             if r['action'] == 'sign_out':
77                 r['delay'] = -r['delay']
78             total += r['delay']
79             if abs(r['delay'].seconds) < max * 60:
80                 total2 += r['delay']
81
82         result_dict = {
83                 'total' : total and str(total).split('.')[0],
84                 'total2' : total2  and  str(total2).split('.')[0]
85                 }
86 #        return (self._sign(total),total2 and self._sign(total2))
87         return [result_dict]
88
89 report_sxw.report_sxw('report.hr.attendance.error', 'hr.employee', 'addons/hr_attendance/report/attendance_errors.rml', parser=attendance_print, header=2)
90
91
92 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
93