[FIX] Hr_attendance : attendance error report corrected(ref:ach,jvo)
bzr revid: jvo@tinyerp.com-20090424132022-utpvuk213e03qi5h
This commit is contained in:
parent
00a002e314
commit
7a78f28988
|
@ -23,6 +23,8 @@
|
|||
|
||||
import time
|
||||
from report import report_sxw
|
||||
import pooler
|
||||
import datetime
|
||||
|
||||
class attendance_print(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
|
@ -31,26 +33,33 @@ class attendance_print(report_sxw.rml_parse):
|
|||
'time': time,
|
||||
'lst': self._lst,
|
||||
'total': self._lst_total,
|
||||
'get_employees':self._get_employees,
|
||||
})
|
||||
|
||||
def _sign(self, dt):
|
||||
if abs(dt.days)>1:
|
||||
format = '%d day'+(((abs(dt.days)>=2) and 's') or '')+' %H:%M:%S'
|
||||
else:
|
||||
format = '%H:%M:%S'
|
||||
if dt.seconds<0:
|
||||
return dt.strftime('- '+format)
|
||||
else:
|
||||
return dt.strftime(format)
|
||||
def _get_employees(self, emp_ids):
|
||||
emp_obj_list = self.pool.get('hr.employee').browse(self.cr,self.uid,emp_ids)
|
||||
return emp_obj_list
|
||||
|
||||
# def _sign(self, dt):
|
||||
# if abs(dt.days) > 1:
|
||||
# format = '%d day'+(((abs(dt.days)>=2) and 's') or '')+' %H:%M:%S'
|
||||
# else:
|
||||
# format = '%H:%M:%S'
|
||||
# if dt.seconds<0:
|
||||
# return dt.strftime('- '+format)
|
||||
# else:
|
||||
# return dt.strftime(format)
|
||||
|
||||
def _lst(self, employee_id, dt_from, dt_to, max, *args):
|
||||
self.cr.execute('select name as date, create_date, action, create_date-name as delay from hr_attendance where employee_id=%s and name<=%s and name>=%s and action in (%s,%s) order by name', (employee_id, dt_to, dt_from, 'sign_in', 'sign_out'))
|
||||
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'))
|
||||
res = self.cr.dictfetchall()
|
||||
for r in res:
|
||||
if r['action']=='sign_out':
|
||||
r['delay'] = - r['delay']
|
||||
if r['action'] == 'sign_out':
|
||||
r['delay'] = -r['delay']
|
||||
temp = r['delay'].seconds
|
||||
r['delay'] = self._sign(r['delay'])
|
||||
|
||||
# r['delay'] = self._sign(r['delay'])
|
||||
r['delay'] = str(r['delay']).split('.')[0]
|
||||
if abs(temp) < max*60:
|
||||
r['delay2'] = r['delay']
|
||||
else:
|
||||
|
@ -58,21 +67,26 @@ class attendance_print(report_sxw.rml_parse):
|
|||
return res
|
||||
|
||||
def _lst_total(self, employee_id, dt_from, dt_to, max, *args):
|
||||
self.cr.execute('select name as date, create_date, action, create_date-name as delay from hr_attendance where employee_id=%s and name<=%s and name>=%s and action in (%s,%s)', (employee_id, dt_to, dt_from, 'sign_in', 'sign_out'))
|
||||
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'))
|
||||
res = self.cr.dictfetchall()
|
||||
if not res:
|
||||
return ('/','/')
|
||||
total = 0
|
||||
total2 = 0
|
||||
total2 = datetime.timedelta(seconds = 0, minutes = 0, hours = 0)
|
||||
total = datetime.timedelta(seconds = 0, minutes = 0, hours = 0)
|
||||
for r in res:
|
||||
if r['action']=='sign_out':
|
||||
r['delay'] = - r['delay']
|
||||
if r['action'] == 'sign_out':
|
||||
r['delay'] = -r['delay']
|
||||
total += r['delay']
|
||||
if abs(r['delay'].seconds) < max*60:
|
||||
total2 += r['delay']
|
||||
|
||||
return (self._sign(total),total2 and self._sign(total2))
|
||||
|
||||
|
||||
result_dict = {
|
||||
'total' : total and str(total).split('.')[0],
|
||||
'total2' : total2 and str(total2).split('.')[0]
|
||||
}
|
||||
# return (self._sign(total),total2 and self._sign(total2))
|
||||
return [result_dict]
|
||||
|
||||
report_sxw.report_sxw('report.hr.attendance.error', 'hr.employee', 'addons/hr_attendance/report/attendance_errors.rml',parser=attendance_print, header=2)
|
||||
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
</stylesheet>
|
||||
<images/>
|
||||
<story>
|
||||
<para style="terp_default_8">[[ repeatIn(objects,'employee') ]]</para>
|
||||
<para style="terp_default_8">[[ repeatIn(get_employees(data['form']['emp_ids']),'employee') ]]</para>
|
||||
<para style="terp_header_Centre">Attendance Errors</para>
|
||||
<para style="P1">[[ employee.name ]]</para>
|
||||
<para style="terp_default_8">
|
||||
|
@ -140,13 +140,13 @@
|
|||
<blockTable colWidths="357.0,99.0,63.0" style="Table_employee_total">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_default_Bold_9">Total period:</para>
|
||||
<para style="terp_default_Bold_9">Total period:<font face="Times">[[ repeatIn(total(employee.id,data['form']['init_date'], data['form']['end_date'], data['form']['max_delay']),'total')]] </font></para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_Centre_9_Bold">[[ total(employee.id,data['form']['init_date'], data['form']['end_date'], data['form']['max_delay'])[0] ]]</para>
|
||||
<para style="terp_default_Centre_9_Bold">[[ total['total'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_Centre_9_Bold">[[ total(employee.id,data['form']['init_date'], data['form']['end_date'], data['form']['max_delay'])[1] ]]</para>
|
||||
<para style="terp_default_Centre_9_Bold">[[ total['total2'] ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
|
|
|
@ -48,6 +48,15 @@ def _check_data(self, cr, uid, data, *args):
|
|||
attendance_ids = [x[0] for x in cr.fetchall()]
|
||||
if not attendance_ids:
|
||||
raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!'))
|
||||
|
||||
attendance_records = pooler.get_pool(cr.dbname).get('hr.attendance').browse(cr,uid,attendance_ids)
|
||||
emp_ids = []
|
||||
for rec in attendance_records:
|
||||
if rec.employee_id.id not in emp_ids:
|
||||
emp_ids.append(rec.employee_id.id)
|
||||
|
||||
data['form']['emp_ids'] = emp_ids
|
||||
|
||||
return data['form']
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue