2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-03-05 18:22:32 +00:00
|
|
|
##############################################################################
|
2009-10-14 11:15:34 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2007-03-05 18:22:32 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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.
|
2007-03-05 18:22:32 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# 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
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2007-03-05 18:22:32 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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/>.
|
2007-03-05 18:22:32 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
import wizard
|
|
|
|
import netsvc
|
|
|
|
import time
|
|
|
|
import pooler
|
2007-04-11 05:51:27 +00:00
|
|
|
from osv import osv
|
2008-07-08 08:13:12 +00:00
|
|
|
from tools.translate import _
|
2007-03-05 18:22:32 +00:00
|
|
|
|
|
|
|
class wiz_timesheet_open(wizard.interface):
|
2008-07-22 15:11:28 +00:00
|
|
|
def _open_timesheet(self, cr, uid, data, context):
|
|
|
|
pool = pooler.get_pool(cr.dbname)
|
|
|
|
user_ids = pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)])
|
|
|
|
if not len(user_ids):
|
|
|
|
raise wizard.except_wizard(_('Error !'), _('No employee defined for your user !'))
|
|
|
|
ts = pool.get('hr_timesheet_sheet.sheet')
|
|
|
|
ids = ts.search(cr, uid, [('user_id','=',uid),('state','=','draft'),('date_from','<=',time.strftime('%Y-%m-%d')), ('date_to','>=',time.strftime('%Y-%m-%d'))])
|
|
|
|
view_type = 'form,tree'
|
|
|
|
if len(ids) > 1:
|
|
|
|
view_type = 'tree,form'
|
2009-10-21 07:24:49 +00:00
|
|
|
domain = "[('id','in',["+','.join(map(str, ids))+"]),('user_id', '=', uid)]"
|
2008-07-22 15:11:28 +00:00
|
|
|
elif len(ids)==1:
|
|
|
|
ts.write(cr, uid, ids, {'date_current': time.strftime('%Y-%m-%d')})
|
|
|
|
domain = "[('user_id', '=', uid)]"
|
|
|
|
else:
|
|
|
|
domain = "[('user_id', '=', uid)]"
|
|
|
|
value = {
|
|
|
|
'domain': domain,
|
|
|
|
'name': 'Open timesheet',
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': view_type,
|
|
|
|
'res_model': 'hr_timesheet_sheet.sheet',
|
|
|
|
'view_id': False,
|
|
|
|
'type': 'ir.actions.act_window'
|
|
|
|
}
|
|
|
|
if len(ids) == 1:
|
|
|
|
value['res_id'] = ids[0]
|
|
|
|
return value
|
2007-03-05 18:22:32 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
states = {
|
|
|
|
'init' : {
|
|
|
|
'actions' : [],
|
|
|
|
'result' : {'type':'action', 'action':_open_timesheet, 'state':'end'}
|
|
|
|
}
|
|
|
|
}
|
2007-03-05 18:22:32 +00:00
|
|
|
wiz_timesheet_open('hr_timesheet_sheet.current.open')
|
|
|
|
|
2008-07-23 14:41:47 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|