~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to hr_timesheet_project/wizard/timesheet_hour_encode.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
 
 
30
import wizard
 
31
import netsvc
 
32
import time
 
33
 
 
34
import pooler
 
35
from osv import osv
 
36
 
 
37
def _action_line_create(self, cr, uid, data, context):
 
38
        tw = pooler.get_pool(cr.dbname).get('project.task.work')
 
39
        ids = tw.search(cr, uid, [('user_id','=',uid), ('date','>=',time.strftime('%Y-%m-%d 00:00:00')), ('date','<=',time.strftime('%Y-%m-%d 23:59:59'))])
 
40
        ts =  pooler.get_pool(cr.dbname).get('hr.analytic.timesheet')
 
41
 
 
42
        for work in tw.browse(cr, uid, ids, context):
 
43
                if work.task_id.project_id.category_id:
 
44
                        unit_id = ts._getEmployeeUnit(cr, uid, context)
 
45
                        product_id = ts._getEmployeeUnit(cr, uid, context)
 
46
                        res = {
 
47
                                'name': work.name,
 
48
                                'date': time.strftime('%Y-%m-%d'),
 
49
                                'unit_amount': work.hours,
 
50
                                'product_uom_id': unit_id,
 
51
                                'product_id': product_id,
 
52
                                'amount': work.hours or 0.0,
 
53
                                'account_id': work.task_id.project_id.category_id.id
 
54
                        }
 
55
                        res2 = ts.on_change_unit_amount(cr, uid, False, product_id, work.hours or 0.0,unit_id, context)
 
56
                        if res2:
 
57
                                res.update(res2['value'])
 
58
                        id = ts.create(cr, uid, res, context)
 
59
                else:
 
60
                        print 'not found', work.task_id.project_id.name
 
61
 
 
62
        value = {
 
63
                'domain': "[('user_id','=',%d),('date','>=','%s'), ('date','<=','%s')]" % (uid, time.strftime('%Y-%m-%d 00:00:00'), time.strftime('%Y-%m-%d 23:59:59')),
 
64
                'name': 'Create Analytic Line',
 
65
                'view_type': 'form',
 
66
                'view_mode': 'tree,form',
 
67
                'res_model': 'hr.analytic.timesheet',
 
68
                'view_id': False,
 
69
                'type': 'ir.actions.act_window'
 
70
        }
 
71
        return value
 
72
 
 
73
class wiz_hr_timesheet_project(wizard.interface):
 
74
        states = {
 
75
                'init': {
 
76
                        'actions': [],
 
77
                        'result': {'type': 'action', 'action': _action_line_create, 'state':'end'}
 
78
                }
 
79
        }
 
80
wiz_hr_timesheet_project('hr_timesheet_project.encode.hour')
 
81