1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
26 _date_form = '''<?xml version="1.0"?>
27 <form string="Select a time span">
28 <separator string="Analysis Information" colspan="4"/>
29 <field name="init_date"/>
30 <field name="end_date"/>
31 <field name="max_delay"/>
32 <label string="Bellow this delay, the error is considered to be voluntary" colspan="2"/>
36 'init_date': {'string':'Starting Date', 'type':'date', 'default':lambda *a: time.strftime('%Y-%m-%d'), 'required':True},
37 'end_date': {'string':'Ending Date', 'type':'date', 'default':lambda *a: time.strftime('%Y-%m-%d'), 'required':True},
38 'max_delay': {'string':'Max. Delay (Min)', 'type':'integer', 'default':lambda *a: 120, 'required':True},
41 def _check_data(self, cr, uid, data, *args):
42 date_from = data['form']['init_date']
43 date_to = data['form']['end_date']
44 emp_ids = (','.join([str(x) for x in data['ids']]))
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','%s') order by name" %(emp_ids, date_to, date_from, 'sign_in', 'sign_out'))
47 attendance_ids = [x[0] for x in cr.fetchall()]
48 if not attendance_ids:
49 raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!'))
51 attendance_records = pooler.get_pool(cr.dbname).get('hr.attendance').browse(cr,uid,attendance_ids)
53 for rec in attendance_records:
54 if rec.employee_id.id not in emp_ids:
55 emp_ids.append(rec.employee_id.id)
57 data['form']['emp_ids'] = emp_ids
62 class wiz_attendance(wizard.interface):
66 'result': {'type': 'form', 'arch':_date_form, 'fields':_date_fields, 'state':[('print','Print Attendance Report'),('end','Cancel') ]}
69 'actions': [_check_data],
70 'result': {'type': 'print', 'report': 'hr.attendance.error', 'state':'end'}
73 wiz_attendance('hr.attendance.report')
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: