[IMP] srcum:Improved wizards for converting backlogs to task
[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     state_open = data['form']['state_open']
53     convert_to_task = data['form']['convert_to_task']
54     for backlog in backlog_obj.browse(cr, uid, data['ids'], context=context):
55         backlog_obj.write(cr, uid, backlog.id, {'sprint_id':data['form']['sprint_id']}, context=context)
56         if convert_to_task:
57             task.create(cr, uid, {
58                 'product_backlog_id': backlog.id,
59                 'name': backlog.name,
60                 'description': backlog.note,
61                 'project_id': backlog.project_id.id,
62                 'user_id': False,
63                 'planned_hours':backlog.planned_hours,
64                 'remaining_hours':backlog.expected_hours,
65             })
66         if state_open:
67             if backlog.state == "draft":
68                 backlog_obj.write(cr, uid, backlog.id, {'state':'open'})
69     return {}
70
71 class wiz_bts(wizard.interface):
72     states = {
73         'init':{
74             'actions': [],
75             'result': {'type':'form', 'arch':bts_form, 'fields':bts_fields, 'state':[('end', 'Cancel'), ('assign', 'Assign Sprint')] },
76         },
77         'assign':{
78             'actions': [],
79             'result': {'type':'action', 'action': _assign_sprint, 'state':'end'},
80         },
81     }
82 wiz_bts('scrum.product.backlog.sprint.assign')
83
84
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
86