added from extra-addons
[odoo/odoo.git] / addons / project_gtd / wizard / project_gtd_fill.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #
6 # $Id: sign_in_out.py 2871 2006-04-25 14:08:22Z fp $
7 #
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 #
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28 #
29 ##############################################################################
30
31
32 import wizard
33 import pooler
34 from osv import osv
35
36 _gtd_field = {
37     'task_ids': {'relation':'project.task', 'type':'many2many', 'string':'Tasks selection'},
38     'timebox_to_id': {'relation':'project.gtd.timebox', 'type':'many2one', 'string':'Set to Timebox'},
39     'timebox_id': {'relation':'project.gtd.timebox', 'type':'many2one', 'string':'Get from Timebox'}
40 }
41
42 _gtd_arch = """
43     <form string="Timebox tasks selection" width="780">
44         <field name="timebox_id" required="1"/>
45         <field name="timebox_to_id" required="1"/>
46         <field name="task_ids" nolabel="1" colspan="4" height="450" domain="[('timebox_id','=',timebox_id),('state','=','open')]"/>
47     </form>
48 """
49
50 class wiz_timebox_fill(wizard.interface):
51     def _fill(self, cr, uid, data, context):
52         pool = pooler.get_pool(cr.dbname)
53         ids = pool.get('project.gtd.timebox').search(cr, uid, [('parent_id','=',data['id']),('user_id','=',uid)], context=context)
54         return {
55             'timebox_id': ids and ids[0] or False,
56             'timebox_to_id': data['id']
57         }
58
59     def _process(self, cr, uid, data, context):
60         pool = pooler.get_pool(cr.dbname)
61         ids = data['form']['task_ids']
62         pool.get('project.task').write(cr, uid, ids[0][2], {'timebox_id':data['form']['timebox_to_id']})
63         return {}
64
65     states = {
66         'init' : {
67             'actions' : [_fill],
68             'result' : {
69                 'type':'form',
70                 'arch':_gtd_arch,
71                 'fields':_gtd_field,
72                 'state':[
73                     ('end','Cancel'),
74                     ('process','Add to Timebox')
75                 ]
76             }
77         },
78         'process' : {
79             'actions' : [_process],
80             'result' : {'type':'state', 'state':'end'}
81         }
82     }
83 wiz_timebox_fill('project.gtd.timebox.fill')
84
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
86