diff --git a/addons/hr_timesheet/__openerp__.py b/addons/hr_timesheet/__openerp__.py
index a917ed2df4c..4bd6d3525fc 100644
--- a/addons/hr_timesheet/__openerp__.py
+++ b/addons/hr_timesheet/__openerp__.py
@@ -46,7 +46,8 @@ to set up a management by affair.
'hr_timesheet_wizard.xml',
'process/hr_timesheet_process.xml',
'wizard/hr_timesheet_print_employee_view.xml',
- 'wizard/hr_timesheet_print_users_view.xml'
+ 'wizard/hr_timesheet_print_users_view.xml',
+ 'wizard/hr_timesheet_sign_in_out_view.xml',
],
'demo_xml': ['hr_timesheet_demo.xml'],
'installable': True,
diff --git a/addons/hr_timesheet/hr_timesheet_wizard.xml b/addons/hr_timesheet/hr_timesheet_wizard.xml
index f0a2d7175b3..fa36c03ae10 100644
--- a/addons/hr_timesheet/hr_timesheet_wizard.xml
+++ b/addons/hr_timesheet/hr_timesheet_wizard.xml
@@ -1,8 +1,8 @@
-
+
diff --git a/addons/hr_timesheet/wizard/__init__.py b/addons/hr_timesheet/wizard/__init__.py
index 8619dcbcfea..5f2bc1443e3 100644
--- a/addons/hr_timesheet/wizard/__init__.py
+++ b/addons/hr_timesheet/wizard/__init__.py
@@ -19,7 +19,7 @@
#
##############################################################################
-import sign_in_out
+import hr_timesheet_sign_in_out
import hr_timesheet_print_employee
import hr_timesheet_print_users
diff --git a/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py b/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py
new file mode 100644
index 00000000000..fa57cfdd1a5
--- /dev/null
+++ b/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py
@@ -0,0 +1,169 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# 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 .
+#
+##############################################################################
+import time
+
+from osv import osv, fields
+from tools.translate import _
+
+class hr_so_project(osv.osv_memory):
+ _name = 'hr.sign.out.project'
+ _description = 'Sign Out By Project'
+ _columns = {
+ 'account_id': fields.many2one('account.analytic.account', 'Analytic Account', required=True, domain=[('type','=','normal')]),
+ 'info': fields.char('Work Description', size=256, required=True),
+ 'date_start': fields.datetime('Starting Date', readonly=True),
+ 'date': fields.datetime('Closing Date'),
+ 'analytic_amount': fields.float('Minimum Analytic Amount'),
+ 'name': fields.char('Employees name', size=32, required=True, readonly=True),
+ 'state': fields.char('Current state', size=32, required=True, readonly=True),
+ 'server_date': fields.datetime('Current Date', required=True, readonly=True),
+ 'emp_id': fields.char('Employee ID', size=256, required=False),
+ }
+
+ def _get_empid(self, cr, uid, context=None):
+ emp_obj = self.pool.get('hr.employee')
+ emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
+ if emp_id:
+ employee = emp_obj.read(cr, uid, emp_id)[0]
+ return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0], 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')}
+ raise osv.except_osv(_('UserError'), _('No employee defined for your user !'))
+
+ def _get_empid2(self, cr, uid, context):
+ res = self._get_empid(cr, uid, context)
+ cr.execute('select name,action from hr_attendance where employee_id=%s order by name desc limit 1', (res['emp_id'],))
+ res['server_date'] = time.strftime('%Y-%m-%d %H:%M:%S')
+ res['date_start'] = cr.fetchone()[0]
+ return res
+
+ def default_get(self, cr, uid, fields_list, context=None):
+ res = super(hr_so_project, self).default_get(cr, uid, fields_list, context=context)
+ res.update(self._get_empid2(cr, uid, context=context))
+ return res
+
+ def _write(self, cr, uid, data, emp_id, context=None):
+ timesheet_obj = self.pool.get('hr.analytic.timesheet')
+ emp_obj = self.pool.get('hr.employee')
+ hour = (time.mktime(time.strptime(data['date'] or time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')) -
+ time.mktime(time.strptime(data['date_start'], '%Y-%m-%d %H:%M:%S'))) / 3600.0
+ minimum = data['analytic_amount']
+ if minimum:
+ hour = round(round((hour + minimum / 2) / minimum) * minimum, 2)
+ res = timesheet_obj.default_get(cr, uid, ['product_id','product_uom_id'])
+ if not res['product_uom_id']:
+ raise osv.except_osv(_('UserError'), _('No cost unit defined for this employee !'))
+ up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour, res['product_uom_id'])['value']
+ res['name'] = data['info']
+ res['account_id'] = data['account_id']
+ res['unit_amount'] = hour
+ emp_journal = emp_obj.browse(cr, uid, emp_id, context).journal_id
+ res['journal_id'] = emp_journal and emp_journal.id or False
+ res.update(up)
+ up = timesheet_obj.on_change_account_id(cr, uid, [], res['account_id']).get('value', {})
+ res.update(up)
+ return timesheet_obj.create(cr, uid, res, context=context)
+
+ def sign_out_result_end(self, cr, uid, ids, context=None):
+ emp_obj = self.pool.get('hr.employee')
+ data = self.read(cr, uid, ids, [])[0]
+ emp_id = data['emp_id']
+ emp_obj.attendance_action_change(cr, uid, [emp_id], type='sign_out',dt=data['date'])
+ self._write(cr, uid, data, emp_id, context=context)
+ return {}
+
+ def sign_out_result(self, cr, uid, ids, context=None):
+ emp_obj = self.pool.get('hr.employee')
+ data = self.read(cr, uid, ids, [])[0]
+ emp_id = data['emp_id']
+ emp_obj.attendance_action_change(cr, uid, [emp_id], type='action', dt=data['date'])
+ self._write(cr, uid, data, emp_id, context=context)
+ return {}
+
+hr_so_project()
+
+class hr_si_project(osv.osv_memory):
+ _name = 'hr.sign.in.project'
+ _description = 'Sign In By Project'
+ _columns = {
+ 'name': fields.char('Employees name', size=32, required=True, readonly=True),
+ 'state': fields.char('Current state', size=32, required=True, readonly=True),
+ 'date': fields.datetime('Starting Date'),
+ 'server_date': fields.datetime('Current Date', required=True, readonly=True),
+ 'emp_id': fields.char('Employee ID', size=512, required=False),
+ }
+
+ def check_state(self, cr, uid, ids, context=None):
+ obj_model = self.pool.get('ir.model.data')
+ emp_id = self._get_empid(cr, uid, context)['emp_id']
+ # get the latest action (sign_in or out) for this employee
+ cr.execute('select action from hr_attendance where employee_id=%s and action in (\'sign_in\',\'sign_out\') order by name desc limit 1', (emp_id,))
+ res = (cr.fetchone() or ('sign_out',))[0]
+ #TODO: invert sign_in et sign_out
+ if res == 'sign_out':
+ model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_hr_timesheet_sign_in')])
+ resource_id = obj_model.read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
+ return {
+ 'name': 'Sign in / Sign out',
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'hr.sign.in.project',
+ 'views': [(False,'tree'), (resource_id,'form')],
+ 'type': 'ir.actions.act_window',
+ 'target': 'new'
+ }
+ else:
+ model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_hr_timesheet_sign_out')])
+ resource_id = obj_model.read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
+ return {
+ 'name': 'Sign in / Sign out',
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'hr.sign.out.project',
+ 'views': [(False,'tree'), (resource_id,'form')],
+ 'type': 'ir.actions.act_window',
+ 'target': 'new'
+ }
+
+ def _get_empid(self, cr, uid, context=None):
+ emp_obj = self.pool.get('hr.employee')
+ emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
+ if emp_id:
+ employee = emp_obj.read(cr, uid, emp_id)[0]
+ return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0], 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')}
+ raise osv.except_osv(_('UserError'), _('No employee defined for your user !'))
+
+ def sign_in_result(self, cr, uid, ids, context):
+ emp_obj = self.pool.get('hr.employee')
+ data = self.read(cr, uid, ids, [], context)[0]
+ emp_id = data['emp_id']
+ try:
+ success = emp_obj.attendance_action_change(cr, uid, [emp_id], type = 'sign_in' ,dt=data['date'] or False)
+ except except_osv, e:
+ raise osv.except_osv(e.name, e.value)
+ return {}
+
+ def default_get(self, cr, uid, fields_list, context=None):
+ res = super(hr_si_project, self).default_get(cr, uid, fields_list, context=context)
+ res.update(self._get_empid(cr, uid, context=context))
+ return res
+
+hr_si_project()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out_view.xml b/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out_view.xml
new file mode 100644
index 00000000000..487208bfbf6
--- /dev/null
+++ b/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out_view.xml
@@ -0,0 +1,95 @@
+
+
+
+
+ hr.sign.in.project.message.form
+ hr.sign.in.project
+ form
+
+
+
+
+
+
+ hr.sign.in.project.form
+ hr.sign.in.project
+ form
+
+
+
+
+
+
+ Sign in / Sign out by project
+ hr.sign.in.project
+ form
+ tree,form
+
+ new
+
+
+
+
+
+ hr.sign.out.project.form
+ hr.sign.out.project
+ form
+
+
+
+
+
+
+ Sign in / Sign out by project
+ hr.sign.out.project
+ form
+ tree,form
+
+ new
+
+
+
+
diff --git a/addons/hr_timesheet/wizard/sign_in_out.py b/addons/hr_timesheet/wizard/sign_in_out.py
deleted file mode 100644
index ff532afc260..00000000000
--- a/addons/hr_timesheet/wizard/sign_in_out.py
+++ /dev/null
@@ -1,174 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# 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 .
-#
-##############################################################################
-
-
-import wizard
-import time
-import pooler
-from tools.translate import _
-
-si_form ='''
-'''
-
-si_fields = {
- 'name': {'string': "Employee's name", 'type':'char', 'required':True, 'readonly':True},
- 'state': {'string': "Current state", 'type' : 'char', 'required' : True, 'readonly': True},
- 'date': {'string':"Starting Date", 'type':'datetime'},
- 'server_date': {'string':"Current Date", 'type':'datetime', 'readonly':True},
-}
-
-so_form = '''
-'''
-
-so_fields = {
- 'name': {'string':"Employee's name", 'type':'char', 'required':True, 'readonly':True},
- 'state': {'string':"Current state", 'type':'char', 'required':True, 'readonly':True},
- 'account_id': {'string':"Analytic Account", 'type':'many2one', 'relation':'account.analytic.account', 'required':True, 'domain':"[('type','=','normal')]"},
- 'info': {'string':"Work Description", 'type':'char', 'size':256, 'required':True},
- 'date': {'string':"Closing Date", 'type':'datetime'},
- 'date_start': {'string':"Starting Date", 'type':'datetime', 'readonly':True},
- 'server_date': {'string':"Current Server Date", 'type':'datetime', 'readonly':True},
- 'analytic_amount': {'string':"Minimum Analytic Amount", 'type':'float'},
-}
-
-def _get_empid(self, cr, uid, data, context):
- emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
- emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
- if emp_id:
- employee = emp_obj.read(cr, uid, emp_id)[0]
- return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0], 'date':False, 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')}
- raise wizard.except_wizard(_('UserError'), _('No employee defined for your user !'))
-
-def _get_empid2(self, cr, uid, data, context):
- res = _get_empid(self,cr, uid, data, context)
- cr.execute('select name,action from hr_attendance where employee_id=%s order by name desc limit 1', (res['emp_id'],))
- res['server_date'] = time.strftime('%Y-%m-%d %H:%M:%S')
- res['date_start'] = cr.fetchone()[0]
- res['info'] = ''
- res['account_id'] = False
- return res
-
-def _sign_in_result(self, cr, uid, data, context):
- emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
- emp_id = data['form']['emp_id']
- from osv.osv import except_osv
- try:
- success = emp_obj.attendance_action_change(cr, uid, [emp_id], type = 'sign_in' ,dt=data['form']['date'] or False)
- except except_osv, e:
- raise wizard.except_wizard(e.name, e.value)
- return {}
-
-def _write(self, cr, uid, data, emp_id, context):
- timesheet_obj = pooler.get_pool(cr.dbname).get('hr.analytic.timesheet')
- emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
- hour = (time.mktime(time.strptime(data['form']['date'] or time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')) -
- time.mktime(time.strptime(data['form']['date_start'], '%Y-%m-%d %H:%M:%S'))) / 3600.0
- minimum = data['form']['analytic_amount']
- if minimum:
- hour = round(round((hour + minimum / 2) / minimum) * minimum, 2)
- res = timesheet_obj.default_get(cr, uid, ['product_id','product_uom_id'])
- if not res['product_uom_id']:
- raise wizard.except_wizard(_('UserError'), _('No cost unit defined for this employee !'))
- up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour, res['product_uom_id'])['value']
- res['name'] = data['form']['info']
- res['account_id'] = data['form']['account_id']
- res['unit_amount'] = hour
- emp_journal = emp_obj.browse(cr, uid, emp_id, context).journal_id
- res['journal_id'] = emp_journal and emp_journal.id or False
- res.update(up)
- up = timesheet_obj.on_change_account_id(cr, uid, [], res['account_id']).get('value', {})
- res.update(up)
- return timesheet_obj.create(cr, uid, res, context)
-
-def _sign_out_result_end(self, cr, uid, data, context):
- emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
- emp_id = data['form']['emp_id']
- emp_obj.attendance_action_change(cr, uid, [emp_id], type='sign_out',dt=data['form']['date'])
- _write(self, cr, uid, data, emp_id, context)
- return {}
-
-def _sign_out_result(self, cr, uid, data, context):
- emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
- emp_id = data['form']['emp_id']
- emp_obj.attendance_action_change(cr, uid, [emp_id], type='action',dt=data['form']['date'])
- _write(self, cr, uid, data, emp_id, context)
- return {}
-
-def _state_check(self, cr, uid, data, context):
- emp_id = _get_empid(self, cr, uid, data, context)['emp_id']
- # get the latest action (sign_in or out) for this employee
- cr.execute('select action from hr_attendance where employee_id=%s and action in (\'sign_in\',\'sign_out\') order by name desc limit 1', (emp_id,))
- res = (cr.fetchone() or ('sign_out',))[0]
-#TODO: invert sign_in et sign_out
- return res
-
-class wiz_si_so(wizard.interface):
- states = {
- 'init' : {
- 'actions' : [_get_empid],
- 'result' : {'type' : 'choice', 'next_state': _state_check}
- },
- 'sign_out' : { # this means sign_in...
- 'actions' : [_get_empid],
- 'result' : {'type':'form', 'arch':si_form, 'fields' : si_fields, 'state':[('end', 'Cancel'),('si_result', 'Start Working') ] }
- },
- 'si_result' : {
- 'actions' : [_sign_in_result],
- 'result' : {'type':'state', 'state':'end'}
- },
- 'sign_in' : { # this means sign_out...
- 'actions' : [_get_empid2],
- 'result' : {'type':'form', 'arch':so_form, 'fields':so_fields, 'state':[('end', 'Cancel'),('so_result', 'Change Work'),('so_result_end', 'Stop Working') ] }
- },
- 'so_result' : {
- 'actions' : [_sign_out_result],
- 'result' : {'type':'state', 'state':'end'}
- },
- 'so_result_end' : {
- 'actions' : [_sign_out_result_end],
- 'result' : {'type':'state', 'state':'end'}
- },
- }
-wiz_si_so('hr_timesheet.si_so')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-