Launchpad automatic translations update.
[odoo/odoo.git] / addons / hr_attendance / wizard / hr_attendance_error.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 import time
22
23 from osv import osv, fields
24 from tools.translate import _
25
26 class hr_attendance_error(osv.osv_memory):
27
28     _name = 'hr.attendance.error'
29     _description = 'Print Error Attendance Report'
30     _columns = {
31         'init_date': fields.date('Starting Date', required=True),
32         'end_date': fields.date('Ending Date', required=True),
33         'max_delay': fields.integer('Max. Delay (Min)', required=True)
34     }
35     _defaults = {
36          'init_date': lambda *a: time.strftime('%Y-%m-%d'),
37          'end_date': lambda *a: time.strftime('%Y-%m-%d'),
38          'max_delay': 120,
39     }
40
41     def print_report(self, cr, uid, ids, context=None):
42         emp_ids = []
43         data_error = self.read(cr, uid, ids, context=context)[0]
44         date_from = data_error['init_date']
45         date_to = data_error['end_date']
46         cr.execute("SELECT id FROM hr_attendance WHERE employee_id IN %s AND to_char(name,'YYYY-mm-dd')<=%s AND to_char(name,'YYYY-mm-dd')>=%s AND action IN %s ORDER BY name" ,(tuple(context['active_ids']), date_to, date_from, tuple(['sign_in','sign_out'])))
47         attendance_ids = [x[0] for x in cr.fetchall()]
48         if not attendance_ids:
49             raise osv.except_osv(_('No Data Available'), _('No records found for your selection!'))
50         attendance_records = self.pool.get('hr.attendance').browse(cr, uid, attendance_ids, context=context)
51
52         for rec in attendance_records:
53             if rec.employee_id.id not in emp_ids:
54                 emp_ids.append(rec.employee_id.id)
55         data_error['emp_ids'] = emp_ids
56         datas = {
57              'ids': [],
58              'model': 'hr.employee',
59              'form': data_error
60         }
61         return {
62             'type': 'ir.actions.report.xml',
63             'report_name': 'hr.attendance.error',
64             'datas': datas,
65         }
66
67 hr_attendance_error()
68
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: