Added timesheet improved
[odoo/odoo.git] / addons / hr_timesheet_sheet / wizard / wizard_timesheet_current.py
1 ##############################################################################
2 #
3 # Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # $Id: sign_in_out.py 2871 2006-04-25 14:08:22Z ged $
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28 ##############################################################################
29
30
31 import wizard
32 import netsvc
33 import time
34 import pooler
35
36 class wiz_timesheet_open(wizard.interface):
37         def _open_timesheet(self, cr, uid, data, context):
38                 ts = pooler.get_pool(cr.dbname).get('hr_timesheet_sheet.sheet')
39                 ids = ts.search(cr, uid, [('user_id','=',uid),('state','=','draft'),('date_from','<=',time.strftime('%Y-%m-%d')), ('date_to','>=',time.strftime('%Y-%m-%d'))])
40                 view_type = 'form,tree'
41                 if len(ids) > 1:
42                         view_type = 'tree,form'
43                         domain = "[('id','in',["+','.join(map(str,ids))+"])]"
44                 elif len(ids)==1:
45                         ts.write(cr, uid, ids, {'date_current': time.strftime('%y-%m-%d')})
46                         domain = "[]"
47                 else:
48                         domain = "[]"
49                 value = {
50                         'domain': domain,
51                         'name': 'Open timesheet',
52                         'view_type': 'form',
53                         'view_mode': view_type,
54                         'res_model': 'hr_timesheet_sheet.sheet',
55                         'view_id': False,
56                         'type': 'ir.actions.act_window'
57                 }
58                 if len(ids) == 1:
59                         value['res_id'] = ids[0]
60                 print '-'*50
61                 print value
62                 return value
63
64         states = {
65                 'init' : {
66                         'actions' : [],
67                         'result' : {'type':'action', 'action':_open_timesheet, 'state':'end'}
68                 }
69         }
70 wiz_timesheet_open('hr_timesheet_sheet.current.open')
71
72 # vim:noexpandtab:tw=0