35c2852325b14d36cd3ea6b29725e4d1c5cf93d2
[odoo/odoo.git] / addons / scrum / wizard / assign_backlog_to_sprint.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22 import wizard
23 import ir
24 from mx.DateTime import now
25 import pooler
26 import netsvc
27
28 bts_form = """<?xml version="1.0" ?>
29 <form string="Assign Sprint">
30     <group>
31     <field name="sprint_id" colspan="2"/>
32     </group>
33     <newline/>
34     <separator colspan="2"/>
35     <newline/>
36     <group>
37     <field name="state_open" colspan="1"/>
38     <field name="convert_to_task" colspan="1"/>
39     </group>
40 </form>"""
41
42 bts_fields = {
43     'sprint_id' : {'string':'Sprint Name', 'type':'many2one', 'relation':'scrum.sprint', 'required':True},
44     'state_open' : {'string':'Set Open', 'type':'boolean'},
45     'convert_to_task' : {'string':'Convert To Task', 'type':'boolean'}
46 }
47
48 def _assign_sprint(self, cr, uid, data, context):
49     pool = pooler.get_pool(cr.dbname)
50     backlog_obj = pool.get('scrum.product.backlog')
51     task = pool.get('project.task') 
52     
53     state_open=data['form']['state_open']
54     convert_to_task = data['form']['convert_to_task']
55     
56     for backlog in backlog_obj.browse(cr, uid, data['ids']):
57         backlog_obj.write(cr, uid, backlog.id, {'sprint_id':data['form']['sprint_id']})
58         if convert_to_task:
59             task.create(cr, uid, {
60                 'product_backlog_id': backlog.id,
61                 'name': backlog.name,
62                 'description': backlog.note,
63                 'project_id': backlog.project_id.id,
64                 'user_id': (backlog.user_id and backlog.user_id.id) or uid,
65                 'planned_hours': backlog.planned_hours
66             })
67         if state_open:
68             if backlog.state == "draft":
69                 backlog_obj.write(cr, uid, backlog.id, {'state':'open'})
70     return {}
71
72 class wiz_bts(wizard.interface):
73     states = {
74         'init':{
75             'actions': [],
76             'result': {'type':'form', 'arch':bts_form, 'fields':bts_fields, 'state':[('end', 'Cancel'), ('assign', 'Assign Sprint')] },
77         },
78         'assign':{
79             'actions': [],
80             'result': {'type':'action', 'action': _assign_sprint, 'state':'end'},
81         },
82     }
83 wiz_bts('scrum.product.backlog.sprint.assign')
84
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
87