modified files
bzr revid: solanki.priyesh@gmail.com-20080916142547-sejpe7rcv3wg19gi
This commit is contained in:
parent
09a2d50f1b
commit
54f43dd46e
115
addons/hr/hr.py
115
addons/hr/hr.py
|
@ -97,26 +97,6 @@ class hr_employee(osv.osv):
|
|||
_name = "hr.employee"
|
||||
_description = "Employee"
|
||||
|
||||
def _state(self, cr, uid, ids, name, args, context={}):
|
||||
result = {}
|
||||
for id in ids:
|
||||
result[id] = 'absent'
|
||||
cr.execute('SELECT hr_attendance.action, hr_attendance.employee_id \
|
||||
FROM ( \
|
||||
SELECT MAX(name) AS name, employee_id \
|
||||
FROM hr_attendance \
|
||||
WHERE action in (\'sign_in\', \'sign_out\') \
|
||||
GROUP BY employee_id \
|
||||
) AS foo \
|
||||
LEFT JOIN hr_attendance \
|
||||
ON (hr_attendance.employee_id = foo.employee_id \
|
||||
AND hr_attendance.name = foo.name) \
|
||||
WHERE hr_attendance.employee_id \
|
||||
in (' + ','.join([str(x) for x in ids]) + ')')
|
||||
for res in cr.fetchall():
|
||||
result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent'
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char("Employee", size=128, required=True),
|
||||
'active' : fields.boolean('Active'),
|
||||
|
@ -137,55 +117,14 @@ class hr_employee(osv.osv):
|
|||
'work_location': fields.char('Office Location', size=32),
|
||||
|
||||
'notes': fields.text('Notes'),
|
||||
'state': fields.function(_state, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present')], string='Attendance'),
|
||||
|
||||
'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
|
||||
'category_id' : fields.many2one('hr.employee.category', 'Category'),
|
||||
|
||||
'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
|
||||
}
|
||||
_defaults = {
|
||||
'active' : lambda *a: True,
|
||||
'state' : lambda *a: 'absent',
|
||||
}
|
||||
def sign_change(self, cr, uid, ids, context={}, dt=False):
|
||||
for emp in self.browse(cr, uid, ids):
|
||||
if not self._action_check(cr, uid, emp.id, dt, context):
|
||||
raise osv.except_osv(_('Warning'), _('You tried to sign with a date anterior to another event !\nTry to contact the administrator to correct attendances.'))
|
||||
res = {'action':'action', 'employee_id':emp.id}
|
||||
if dt:
|
||||
res['name'] = dt
|
||||
att_id = self.pool.get('hr.attendance').create(cr, uid, res, context=context)
|
||||
return True
|
||||
|
||||
def sign_out(self, cr, uid, ids, context={}, dt=False, *args):
|
||||
id = False
|
||||
for emp in self.browse(cr, uid, ids):
|
||||
if not self._action_check(cr, uid, emp.id, dt, context):
|
||||
raise osv.except_osv(_('Warning'), _('You tried to sign out with a date anterior to another event !\nTry to contact the administrator to correct attendances.'))
|
||||
res = {'action':'sign_out', 'employee_id':emp.id}
|
||||
if dt:
|
||||
res['name'] = dt
|
||||
att_id = self.pool.get('hr.attendance').create(cr, uid, res, context=context)
|
||||
id = att_id
|
||||
return id
|
||||
|
||||
def _action_check(self, cr, uid, emp_id, dt=False,context={}):
|
||||
cr.execute('select max(name) from hr_attendance where employee_id=%d', (emp_id,))
|
||||
res = cr.fetchone()
|
||||
return not (res and (res[0]>=(dt or time.strftime('%Y-%m-%d %H:%M:%S'))))
|
||||
|
||||
def sign_in(self, cr, uid, ids, context={}, dt=False, *args):
|
||||
id = False
|
||||
for emp in self.browse(cr, uid, ids):
|
||||
if not self._action_check(cr, uid, emp.id, dt, context):
|
||||
raise osv.except_osv(_('Warning'), _('You tried to sign in with a date anterior to another event !\nTry to contact the administrator to correct attendances.'))
|
||||
res = {'action':'sign_in', 'employee_id':emp.id}
|
||||
if dt:
|
||||
res['name'] = dt
|
||||
id = self.pool.get('hr.attendance').create(cr, uid, res, context=context)
|
||||
return id
|
||||
|
||||
|
||||
hr_employee()
|
||||
|
||||
class hr_timesheet(osv.osv):
|
||||
|
@ -202,56 +141,4 @@ class hr_timesheet(osv.osv):
|
|||
_order = 'dayofweek, hour_from'
|
||||
hr_timesheet()
|
||||
|
||||
class hr_action_reason(osv.osv):
|
||||
_name = "hr.action.reason"
|
||||
_description = "Action reason"
|
||||
_columns = {
|
||||
'name' : fields.char('Reason', size=64, required=True),
|
||||
'action_type' : fields.selection([('sign_in', 'Sign in'), ('sign_out', 'Sign out')], "Action's type"),
|
||||
}
|
||||
_defaults = {
|
||||
'action_type' : lambda *a: 'sign_in',
|
||||
}
|
||||
hr_action_reason()
|
||||
|
||||
def _employee_get(obj,cr,uid,context={}):
|
||||
ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
if ids:
|
||||
return ids[0]
|
||||
return False
|
||||
|
||||
class hr_attendance(osv.osv):
|
||||
_name = "hr.attendance"
|
||||
_description = "Attendance"
|
||||
_columns = {
|
||||
'name' : fields.datetime('Date', required=True),
|
||||
'action' : fields.selection([('sign_in', 'Sign In'), ('sign_out', 'Sign Out'),('action','Action')], 'Action', required=True),
|
||||
'action_desc' : fields.many2one("hr.action.reason", "Action reason", domain="[('action_type', '=', action)]"),
|
||||
'employee_id' : fields.many2one('hr.employee', 'Employee', required=True, select=True),
|
||||
}
|
||||
_defaults = {
|
||||
'name' : lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'employee_id' : _employee_get,
|
||||
}
|
||||
|
||||
def _altern_si_so(self, cr, uid, ids):
|
||||
for id in ids:
|
||||
sql = '''
|
||||
select action, name
|
||||
from hr_attendance as att
|
||||
where employee_id = (select employee_id from hr_attendance where id=%s)
|
||||
and action in ('sign_in','sign_out')
|
||||
and name <= (select name from hr_attendance where id=%s)
|
||||
order by name desc
|
||||
limit 2
|
||||
''' % (id, id)
|
||||
cr.execute(sql)
|
||||
atts = cr.fetchall()
|
||||
if not ((len(atts)==1 and atts[0][0] == 'sign_in') or (atts[0][0] != atts[1][0] and atts[0][1] != atts[1][1])):
|
||||
return False
|
||||
return True
|
||||
|
||||
_constraints = [(_altern_si_so, 'Error: Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
|
||||
_order = 'name desc'
|
||||
hr_attendance()
|
||||
|
||||
|
|
|
@ -2,31 +2,6 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<record model="hr.action.reason">
|
||||
<field name="name">Start of shift</field>
|
||||
<field name="action_type">sign_in</field>
|
||||
</record>
|
||||
<record model="hr.action.reason">
|
||||
<field name="name">End of shift</field>
|
||||
<field name="action_type">sign_out</field>
|
||||
</record>
|
||||
<record model="hr.action.reason">
|
||||
<field name="name">Meal Break</field>
|
||||
<field name="action_type">sign_in</field>
|
||||
</record>
|
||||
<record model="hr.action.reason">
|
||||
<field name="name">Meal Break</field>
|
||||
<field name="action_type">sign_out</field>
|
||||
</record>
|
||||
<record model="hr.action.reason">
|
||||
<field name="name">Early exit (sick)</field>
|
||||
<field name="action_type">sign_out</field>
|
||||
</record>
|
||||
<record model="hr.action.reason">
|
||||
<field name="name">Early exit (work injury)</field>
|
||||
<field name="action_type">sign_out</field>
|
||||
</record>
|
||||
|
||||
<!-- Example employee -->
|
||||
|
||||
<record id="timesheet_group1" model="hr.timesheet.group">
|
||||
|
@ -111,105 +86,5 @@
|
|||
<field name="tgroup_id" ref="timesheet_group1"/>
|
||||
</record>
|
||||
|
||||
<record id="attendance1" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-01 08:21')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance2" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-01 11:51')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance3" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-02 12:47')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance4" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-02 19:53')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance5" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-03 07:32')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance6" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-03 12:32')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance7" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-04 14:01')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance8" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-04 17:21')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance9" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-05 09:10')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance10" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-05 12:42')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance11" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-06 13:10')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance12" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-06 18:34')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance13" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-07 08:21')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance14" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-07 18:21')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance15" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-08 08:21')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance16" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-08 12:54')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance17" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-09 13:32')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance18" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-09 19:31')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance19" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-10 07:10')" name="name"/>
|
||||
<field name="action">sign_in</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
<record id="attendance20" model="hr.attendance">
|
||||
<field eval="time.strftime('%Y-%m-10 12:34')" name="name"/>
|
||||
<field name="action">sign_out</field>
|
||||
<field name="employee_id" ref="employee1"/>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -49,9 +49,7 @@
|
|||
<group col="4" colspan="2">
|
||||
<separator string="Job Information" colspan="4"/>
|
||||
<field name="parent_id" select="1" colspan="4"/>
|
||||
<field name="state"/>
|
||||
<button name="sign_in" states="absent" string="Sign In" type="object"/>
|
||||
<button name="sign_out" states="present" string="Sign Out" type="object"/>
|
||||
|
||||
<field name="category_id" colspan="4"/>
|
||||
</group>
|
||||
</page>
|
||||
|
@ -75,7 +73,6 @@
|
|||
<field name="work_email"/>
|
||||
<field name="address_id"/>
|
||||
<field name="parent_id"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -142,7 +139,7 @@
|
|||
<field name="name"/>
|
||||
<field name="user_id"/>
|
||||
<field name="address_id"/>
|
||||
<field name="state"/>
|
||||
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -219,34 +216,13 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Attendance -->
|
||||
<record id="view_attendance_form" model="ir.ui.view">
|
||||
<field name="name">hr.attendance.form</field>
|
||||
<field name="model">hr.attendance</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Employee attendance">
|
||||
<field name="employee_id" select="1"/>
|
||||
<field colspan="4" name="name" select="1"/>
|
||||
<field name="action" select="1"/>
|
||||
<field name="action_desc" select="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_attendance_tree" model="ir.ui.view">
|
||||
<field name="name">hr.attendance.tree</field>
|
||||
<field name="model">hr.attendance</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Employee attendances">
|
||||
<field name="name"/>
|
||||
<field name="action"/>
|
||||
<field name="action_desc"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<!--
|
||||
============
|
||||
Employee Category
|
||||
============
|
||||
-->
|
||||
|
||||
<record id="view_employee_category_form" model="ir.ui.view">
|
||||
<record id="view_employee_category_form" model="ir.ui.view">
|
||||
<field name="name">hr.employee.category.form</field>
|
||||
<field name="model">hr.employee.category</field>
|
||||
<field name="type">form</field>
|
||||
|
@ -296,62 +272,6 @@
|
|||
<field name="domain">[('parent_id','=',False)]</field>
|
||||
</record>
|
||||
<menuitem action="open_view_categ_tree" id="menu_view_employee_category_tree" parent="hr.menu_view_employee_category_form"/>
|
||||
|
||||
<record id="view_attendance_who" model="ir.ui.view">
|
||||
<field name="name">hr.attendance.tree</field>
|
||||
<field name="model">hr.attendance</field>
|
||||
<field name="type">tree</field>
|
||||
<field eval="3" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Employee attendance">
|
||||
<field name="employee_id"/>
|
||||
<field name="name"/>
|
||||
<field name="action"/>
|
||||
<field name="action_desc"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="open_view_attendance" model="ir.actions.act_window">
|
||||
<field name="name">Attendances</field>
|
||||
<field name="res_model">hr.attendance</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
<menuitem id="menu_hr_attendance" name="Attendances" parent="hr.menu_hr_root"/>
|
||||
<menuitem action="open_view_attendance" id="menu_open_view_attendance" parent="hr.menu_hr_attendance"/>
|
||||
|
||||
|
||||
<record id="edit_attendance_reason" model="ir.ui.view">
|
||||
<field name="name">hr.action.reason.form</field>
|
||||
<field name="model">hr.action.reason</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Define attendance reason">
|
||||
<field colspan="4" name="name" select="1"/>
|
||||
<field name="action_type" select="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_attendance_reason" model="ir.ui.view">
|
||||
<field name="name">hr.action.reason.tree</field>
|
||||
<field name="model">hr.action.reason</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Attendance reasons">
|
||||
<field name="name"/>
|
||||
<field name="action_type"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="open_view_attendance_reason" model="ir.actions.act_window">
|
||||
<field name="name">Attendance Reasons</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">hr.action.reason</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_attendance_reason"/>
|
||||
</record>
|
||||
<menuitem action="open_view_attendance_reason" id="menu_open_view_attendance_reason" parent="hr.menu_hr_configuration"/>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<wizard id="si_so" model="hr.employee" name="hr.si_so" string="Sign in / Sign out"/>
|
||||
|
||||
<menuitem action="si_so" id="menu_si_so" parent="hr.menu_hr_attendance" type="wizard"/>
|
||||
|
||||
<!-- <wizard id="print_week" keyword="client_print_multi" model="hr.employee" name="hr.print_week" string="Print Timesheet by week"/>
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ from print_byweek import wiz_byweek
|
|||
from print_bymonth import wiz_bymonth
|
||||
import print_attendance_error
|
||||
|
||||
import sign_in_out
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ Lots of reporting on time and employee tracking are provided.
|
|||
It is completly integrated with the cost accounting module. It allows you
|
||||
to set up a management by affair.
|
||||
""",
|
||||
"depends" : ["account", "hr", "base",],
|
||||
"depends" : ["account", "hr", "base", "hr_attendance"],
|
||||
"init_xml" : ["hr_timesheet_data.xml"],
|
||||
"demo_xml" : ["hr_timesheet_demo.xml",],
|
||||
"update_xml" : [
|
||||
|
|
Loading…
Reference in New Issue