[ADD] hr_attnedance: sign in and out wizard => OSV Memory convert

bzr revid: mra@tinyerp.com-20100414092142-4quidut8qyaum8al
This commit is contained in:
mra (Open ERP) 2010-04-14 14:51:42 +05:30
parent 7a9d4468c8
commit 99f3afe6c2
6 changed files with 283 additions and 203 deletions

View File

@ -41,6 +41,7 @@
'wizard/hr_attendance_bymonth_view.xml',
'wizard/hr_attendance_byweek_view.xml',
'wizard/hr_attendance_error_view.xml',
'wizard/hr_attendance_sign_in_out_view.xml',
],
'demo_xml': ['hr_attendance_demo.xml'],
'installable': True,

View File

@ -2,22 +2,22 @@
<openerp>
<data>
<wizard multi="1" menu="False" id="si_so" model="hr.employee" name="hr.si_so" string="Sign in / Sign out"/>
<!--<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="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"/>-->
<menuitem action="si_so" id="menu_si_so" parent="menu_hr_time_tracking" type="wizard" sequence="1"
groups="group_hr_attendance"/>
<!-- <menuitem action="si_so" id="menu_si_so" parent="menu_hr_time_tracking" type="wizard" sequence="1"
groups="group_hr_attendance"/>-->
<!--Time Tracking menu for Project Management-->
<menuitem icon="terp-project" id="base.menu_main_pm" name="Project Management" sequence="1"/>
<menuitem
id="base.menu_project_management_time_tracking"
name="Time Tracking"
parent="base.menu_main_pm" sequence="3"/>
<menuitem action="hr_attendance.si_so" id="menu_project_management_si_so" parent="base.menu_project_management_time_tracking" type="wizard" sequence="9"/>
<!--<menuitem action="hr_attendance.si_so" id="menu_project_management_si_so" parent="base.menu_project_management_time_tracking" type="wizard" sequence="9"/>
-->
</data>
</openerp>

View File

@ -19,7 +19,7 @@
#
##############################################################################
import sign_in_out
import hr_attendance_sign_in_out
import hr_attendance_error
import hr_attendance_byweek
import hr_attendance_bymonth

View File

@ -0,0 +1,185 @@
# -*- 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
import netsvc
from osv import osv, fields
from tools.translate import _
class hr_si_so_ask(osv.osv_memory):
_name = 'hr.sign.in.out.ask'
_description = 'Ask for Sign In Out'
_columns = {
'name': fields.char('Employees name', size=32, required=True, readonly=True),
'last_time': fields.datetime('Your last sign out', required=True),
'emp_id': fields.char('Empoyee ID', size=32, required=True, readonly=True),
}
def _get_empname(self, cr, uid, context=None):
service = netsvc.LocalService('object_proxy')
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
if emp_id:
employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0]
return employee['name']
return ''
def _get_empid(self, cr, uid, context=None):
service = netsvc.LocalService('object_proxy')
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
if emp_id:
return emp_id[0]
return False
_defaults = {
'name': _get_empname,
'emp_id': _get_empid,
}
def sign_in(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids, [])[0]
return self.pool.get('hr.sign.in.out').sign_in(cr, uid, data, context)
def sign_out(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids, [])[0]
return self.pool.get('hr.sign.in.out').sign_out(cr, uid, data, context)
hr_si_so_ask()
class hr_sign_in_out(osv.osv_memory):
_name = 'hr.sign.in.out'
_description = 'Sign In Sign Out'
_columns = {
'name': fields.char('Employees name', size=32, required=True, readonly=True),
'state': fields.char('Current state', size=32, required=True, readonly=True),
'emp_id': fields.char('Empoyee ID', size=32, required=True, readonly=True),
}
def _get_empid(self, cr, uid, context=None):
service = netsvc.LocalService('object_proxy')
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
if emp_id:
employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0]
return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0]}
return {}
def default_get(self, cr, uid, fields_list, context=None):
res = super(hr_sign_in_out, self).default_get(cr, uid, fields_list, context=context)
res_emp = self._get_empid(cr, uid, context=context)
res.update(res_emp)
return res
def si_check(self, cr, uid, ids, context=None):
service = netsvc.LocalService('object_proxy')
obj_model = self.pool.get('ir.model.data')
data = self.read(cr, uid, ids, [])[0]
emp_id = data['emp_id']
att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id)], limit=1, order='name desc')
last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id)
if last_att:
last_att = last_att[0]
cond = not last_att or last_att['action'] == 'sign_out'
if cond:
return self.sign_in(cr, uid, data, context)
else:
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_hr_attendance_so_ask')], context=context)
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'name': _('Sign in / Sign out'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'hr.sign.in.out.ask',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
def so_check(self, cr, uid, ids, context=None):
service = netsvc.LocalService('object_proxy')
obj_model = self.pool.get('ir.model.data')
data = self.read(cr, uid, ids, [])[0]
emp_id = data['emp_id']
att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id),('action','!=','action')], limit=1, order='name desc')
last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id)
if last_att:
last_att = last_att[0]
if not att_id and not last_att:
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_hr_attendance_message')], context=context)
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'name': _('Sign in / Sign out'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'hr.sign.in.out',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
cond = last_att and last_att['action'] == 'sign_in'
if cond:
return self.sign_out(cr, uid, data, context)
else:
model_data_ids = self.pool.get('ir.model.data').search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_hr_attendance_si_ask')], context=context)
resource_id = self.pool.get('ir.model.data').read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'name': _('Sign in / Sign out'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'hr.sign.in.out.ask',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
def sign_in(self, cr, uid, data, context=None):
service = netsvc.LocalService('object_proxy')
emp_id = data['emp_id']
if 'last_time' in data:
if data['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'):
raise osv.except_osv(_('UserError'), _('The sign-out date must be in the past'))
service.execute(cr.dbname, uid, 'hr.attendance', 'create', {
'name': data['last_time'],
'action': 'sign_out',
'employee_id': emp_id
})
try:
success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_in')
except:
raise osv.except_osv(_('UserError'), _('A sign-in must be right after a sign-out !'))
return {} # To do: Return Success message
def sign_out(self, cr, uid, data, context=None):
service = netsvc.LocalService('object_proxy')
emp_id = data['emp_id']
if 'last_time' in data:
if data['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'):
raise osv.except_osv(_('UserError'), _('The Sign-in date must be in the past'))
service.execute(cr.dbname, uid, 'hr.attendance', 'create', {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id})
try:
success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_out')
except:
raise osv.except_osv(_('UserError'), _('A sign-out must be right after a sign-in !'))
return {} # To do: Return Success message
hr_sign_in_out()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_hr_attendance_sigh_in_out" model="ir.ui.view">
<field name="name">hr.sign.in.out.form</field>
<field name="model">hr.sign.in.out</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Sign in / Sign out">
<group colspan="4" >
<separator string="You are now ready to sign in or out of the attendance follow up" colspan="4" />
<field name="name" />
<field name="state" />
</group>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-go-back" string="Sign in" name="si_check" type="object"/>
<button icon="gtk-go-forward" string="Sign out" name="so_check" type="object"/>
</group>
</form>
</field>
</record>
<record id="view_hr_attendance_message" model="ir.ui.view">
<field name="name">hr.sign.in.out.form</field>
<field name="model">hr.sign.in.out</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Sign in / Sign out">
<label string="Sign-Out Entry must follow Sign-In." colspan="4" />
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Ok"/>
</group>
</form>
</field>
</record>
<record id="action_hr_attendance_sigh_in_out" model="ir.actions.act_window">
<field name="name">Sign in / Sign out</field>
<field name="res_model">hr.sign.in.out</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_hr_attendance_sigh_in_out"/>
<field name="target">new</field>
</record>
<menuitem action="action_hr_attendance_sigh_in_out"
id="menu_hr_attendance_sigh_in_out"
parent="menu_hr_time_tracking" groups="group_hr_attendance" />
<record id="view_hr_attendance_so_ask" model="ir.ui.view">
<field name="name">hr.sign.in.out.ask.form</field>
<field name="model">hr.sign.in.out.ask</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="hr.sign.out.ask">
<group colspan="4" >
<separator string="You did not sign out the last time. Please enter the date and time you signed out." colspan="4" />
<field name="name" />
<field name="last_time" string="Your last sign out" />
</group>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-go-back" string="Sign in" name="sign_in" type="object"/>
</group>
</form>
</field>
</record>
<record id="view_hr_attendance_si_ask" model="ir.ui.view">
<field name="name">hr.sign.in.out.ask.form</field>
<field name="model">hr.sign.in.out.ask</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="hr.sign.in.out.ask">
<group colspan="4" >
<separator string="You did not sign in the last time. Please enter the date and time you signed in." colspan="4" />
<field name="name" />
<field name="last_time" string="Your last sign in" />
</group>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-go-back" string="Sign out" name="sign_out" type="object"/>
</group>
</form>
</field>
</record>
</data>
</openerp>

View File

@ -1,197 +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 netsvc
import time
from tools.translate import _
si_so_form ='''<?xml version="1.0"?>
<form string="Sign in / Sign out">
<separator string="You are now ready to sign in or out of the attendance follow up" colspan="4" />
<field name="name" readonly="True" />
<field name="state" readonly="True" />
</form>'''
si_so_fields = {
'name' : {'string' : "Employee's name", 'type':'char', 'required':True, 'readonly':True},
'state' : {'string' : "Current state", 'type' : 'char', 'required' : True, 'readonly': True},
}
si_form = '''<?xml version="1.0" ?>
<form string="Sign in status">
<seperator string="This is the status of your sign in request. Check it out maybe you were already signed in." colspan="4" />
<field name="success" readonly="True" />
</form>'''
si_fields = {
'success' : {'string' : "Sign in's status", 'type' : 'char', 'required' : True, 'readonly' : True},
}
so_form = '''<?xml version="1.0" ?>
<form string="Sign in status">
<seperator string="This is the status of your sign out request. Check it out maybe you were already signed out." colspan="4" />
<field name="success" readonly="True" />
</for>'''
so_fields = {
'success' : {'string' : "Sign out's status", 'type' : 'char', 'required' : True, 'readonly' : True},
}
def _get_empid(self, cr, uid, data, context):
service = netsvc.LocalService('object_proxy')
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
if emp_id:
employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0]
return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0]}
return {}
def _sign_in(self, cr, uid, data, context):
service = netsvc.LocalService('object_proxy')
emp_id = data['form']['emp_id']
if 'last_time' in data['form'] :
if data['form']['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'):
raise wizard.except_wizard(_('UserError'), _('The sign-out date must be in the past'))
return {'success': False}
service.execute(cr.dbname, uid, 'hr.attendance', 'create', {
'name': data['form']['last_time'],
'action': 'sign_out',
'employee_id': emp_id
})
try:
success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_in')
except:
raise wizard.except_wizard(_('UserError'), _('A sign-in must be right after a sign-out !'))
return {'success': success}
def _sign_out(self, cr, uid, data, context):
service = netsvc.LocalService('object_proxy')
emp_id = data['form']['emp_id']
if 'last_time' in data['form'] :
if data['form']['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'):
raise wizard.except_wizard(_('UserError'), _('The Sign-in date must be in the past'))
return {'success': False}
service.execute(cr.dbname, uid, 'hr.attendance', 'create', {'name':data['form']['last_time'], 'action':'sign_in', 'employee_id':emp_id})
try:
success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_out')
except:
raise wizard.except_wizard(_('UserError'), _('A sign-out must be right after a sign-in !'))
return {'success' : success}
so_ask_form ='''<?xml version="1.0"?>
<form string="Sign in / Sign out">
<separator string="You did not sign out the last time. Please enter the date and time you signed out." colspan="4" />
<field name="name" readonly="True" />
<field name="last_time" />
</form>'''
so_ask_fields = {
'name' : {'string' : "Employee's name", 'type':'char', 'required':True, 'readonly':True},
'last_time' : {'string' : "Your last sign out", 'type' : 'datetime', 'required' : True},
}
def _si_check(self, cr, uid, data, context):
states = {True : 'si', False: 'si_ask_so'}
service = netsvc.LocalService('object_proxy')
emp_id = data['form']['emp_id']
att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id)], limit=1, order='name desc')
last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id)
if last_att:
last_att = last_att[0]
cond = not last_att or last_att['action'] == 'sign_out'
return states[cond]
si_ask_form ='''<?xml version="1.0"?>
<form string="Sign in / Sign out">
<separator string="You did not sign in the last time. Please enter the date and time you signed in." colspan="4" />
<field name="name" readonly="True" />
<field name="last_time" />
</form>'''
si_ask_fields = {
'name' : {'string' : "Employee's name", 'type':'char', 'required':True, 'readonly':True},
'last_time' : {'string' : "Your last sign in", 'type' : 'datetime', 'required' : True},
}
so_wo_si_form = '''<?xml version="1.0"?>
<form string="Warning">
<label string="Sign-Out Entry must follow Sign-In." colspan="4" />
</form>'''
def _so_check(self, cr, uid, data, context):
states = {True : 'so', False: 'so_ask_si'}
service = netsvc.LocalService('object_proxy')
emp_id = data['form']['emp_id']
att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id),('action','!=','action')], limit=1, order='name desc')
last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id)
if last_att:
last_att = last_att[0]
if not att_id and not last_att:
return 'so_wo_si'
cond = last_att and last_att['action'] == 'sign_in'
return states[cond]
class wiz_si_so(wizard.interface):
states = {
'init' : {
'actions' : [_get_empid],
'result' : {'type' : 'form', 'arch' : si_so_form, 'fields' : si_so_fields,
'state' : [('end', 'Cancel', 'gtk-cancel'),
('si_test', 'Sign in', 'gtk-go-back'),
('so_test', 'Sign out', 'gtk-go-forward')]
}
},
'si_test' : {
'actions' : [],
'result' : {'type' : 'choice', 'next_state': _si_check}
},
'si_ask_so' : {
'actions' : [],
'result' : {'type' : 'form', 'arch' : so_ask_form, 'fields' : so_ask_fields, 'state' : [('end', 'Cancel'),('si', 'Sign in') ] }
},
'si' : {
'actions' : [_sign_in],
'result' : {'type' : 'state', 'state':'end'}
},
'so_test' : {
'actions' : [],
'result' : {'type' : 'choice', 'next_state': _so_check }
},
'so_ask_si' : {
'actions' : [],
'result' : {'type' : 'form', 'arch' : si_ask_form, 'fields' : si_ask_fields, 'state' : [('end', 'Cancel'),('so', 'Sign out')] }
},
'so' : {
'actions' : [_sign_out],
'result' : {'type' : 'state', 'state':'end'}
},
'so_wo_si' : {
'actions' : [],
'result' : {'type' : 'form', 'arch' : so_wo_si_form, 'fields' : {}, 'state' : [('end', 'Ok')] }
},
}
wiz_si_so('hr.si_so')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: