[ADD] hr_attendance: Print timesheet by error => osv memory

bzr revid: mra@tinyerp.com-20100413070635-uqojhuuaed0qdfcb
This commit is contained in:
mra (Open ERP) 2010-04-13 12:36:35 +05:30
parent 62ed5f7d46
commit 4f203b20b0
6 changed files with 122 additions and 79 deletions

View File

@ -40,6 +40,7 @@
'security/ir.model.access.csv',
'wizard/hr_attendance_bymonth_view.xml',
'wizard/hr_attendance_byweek_view.xml',
'wizard/hr_attendance_error_view.xml',
],
'demo_xml': ['hr_attendance_demo.xml'],
'installable': True,

View File

@ -3,9 +3,9 @@
<data>
<wizard multi="1" menu="False" id="si_so" model="hr.employee" name="hr.si_so" string="Sign in / Sign out"/>
<wizard id="wizard_attendance_error" keyword="client_print_multi" model="hr.employee" name="hr.attendance.report" string="Print Attendance Error Report"/>
<!--<wizard id="wizard_attendance_error" keyword="client_print_multi" model="hr.employee" name="hr.attendance.report" string="Print Attendance Error Report"/>
<wizard id="print_week" keyword="client_print_multi" model="hr.employee" name="hr.attendance.print_week" string="Print Timesheet by week"/>
<wizard id="print_week" keyword="client_print_multi" model="hr.employee" name="hr.attendance.print_week" string="Print Timesheet by week"/>-->
<!--<wizard id="print_month" keyword="client_print_multi" model="hr.employee" name="hr.attendance.print_month" string="Print Timesheet by month"/>-->

View File

@ -20,7 +20,7 @@
##############################################################################
import sign_in_out
import print_attendance_error
import hr_attendance_error
import hr_attendance_byweek
import hr_attendance_bymonth

View File

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from osv import osv, fields
from tools.translate import _
class hr_attendance_error(osv.osv_memory):
_name = 'hr.attendance.error'
_description = 'Print Error Attendance Report'
_columns = {
'init_date': fields.date('Starting Date', required=True),
'end_date': fields.date('Ending Date', required=True),
'max_delay': fields.integer('Max. Delay (Min)', required=True)
}
_defaults = {
'init_date': lambda *a: time.strftime('%Y-%m-%d'),
'end_date': lambda *a: time.strftime('%Y-%m-%d'),
'max_delay': 120,
}
def print_report(self, cr, uid, ids, context=None):
emp_ids = []
data_error = self.read(cr, uid, ids)[0]
date_from = data_error['init_date']
date_to = data_error['end_date']
cr.execute("select id from hr_attendance where employee_id =ANY(%s) and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action =ANY(%s) order by name" ,(context['active_ids'], date_to, date_from, ['sign_in','sign_out']))
attendance_ids = [x[0] for x in cr.fetchall()]
if not attendance_ids:
raise osv.except_osv(_('No Data Available'), _('No records found for your selection!'))
attendance_records = self.pool.get('hr.attendance').browse(cr, uid, attendance_ids)
for rec in attendance_records:
if rec.employee_id.id not in emp_ids:
emp_ids.append(rec.employee_id.id)
data_error['emp_ids'] = emp_ids
datas = {
'ids': [],
'model': 'hr.employee',
'form': data_error
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'hr.attendance.error',
'datas': datas,
}
hr_attendance_error()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_hr_attendance_error" model="ir.ui.view">
<field name="name">Attendance Report Error</field>
<field name="model">hr.attendance.error</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Print Attendance Report Error">
<group col="4" colspan="6">
<separator string="Analysis Information" colspan="4"/>
<field name="init_date"/>
<field name="end_date"/>
<field name="max_delay"/>
<label string="Bellow this delay, the error is considered to be voluntary" colspan="2"/>
<newline/>
</group>
<separator colspan="4"/>
<group col="2" colspan="4">
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
<button name="print_report" string="Print" colspan="1" type="object" icon="gtk-print"/>
</group>
</form>
</field>
</record>
<record id="action_hr_attendance_error" model="ir.actions.act_window">
<field name="name">Print Attendance Error Report</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">hr.attendance.error</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record model="ir.values" id="hr_attendance_error_values">
<field name="model_id" ref="hr.model_hr_employee" />
<field name="object" eval="1" />
<field name="name">Print Attendance Error Report</field>
<field name="key2">client_print_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_hr_attendance_error'))" />
<field name="key">action</field>
<field name="model">hr.employee</field>
</record>
</data>
</openerp>

View File

@ -1,76 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import time
import pooler
from tools.translate import _
_date_form = '''<?xml version="1.0"?>
<form string="Attendance Report">
<separator string="Analysis Information" colspan="4"/>
<field name="init_date"/>
<field name="end_date"/>
<field name="max_delay"/>
<label string="Bellow this delay, the error is considered to be voluntary" colspan="2"/>
</form>'''
_date_fields = {
'init_date': {'string':'Starting Date', 'type':'date', 'default':lambda *a: time.strftime('%Y-%m-%d'), 'required':True},
'end_date': {'string':'Ending Date', 'type':'date', 'default':lambda *a: time.strftime('%Y-%m-%d'), 'required':True},
'max_delay': {'string':'Max. Delay (Min)', 'type':'integer', 'default':lambda *a: 120, 'required':True},
}
def _check_data(self, cr, uid, data, *args):
date_from = data['form']['init_date']
date_to = data['form']['end_date']
cr.execute("select id from hr_attendance where employee_id =ANY(%s) and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action =ANY(%s) order by name" ,(data['ids'], date_to, date_from, ['sign_in','sign_out']))
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']
class wiz_attendance(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':_date_form, 'fields':_date_fields, 'state':[('end','Cancel', 'gtk-cancel'),('print','Print', 'gtk-ok') ]}
},
'print': {
'actions': [_check_data],
'result': {'type': 'print', 'report': 'hr.attendance.error', 'state':'end'}
}
}
wiz_attendance('hr.attendance.report')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: