[MERGE] merge with main branch
[odoo/odoo.git] / addons / project_scrum / wizard / project_scrum_backlog_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 from osv import osv, fields
22 from tools.translate import _
23
24 class backlog_sprint_assign(osv.osv_memory):
25     _name = 'project.scrum.backlog.assign.sprint'
26     _description = 'Assign sprint to backlogs'
27     _columns = {
28         'sprint_id': fields.many2one('project.scrum.sprint', 'Sprint', required=True, help="Select Sprint to assign backlog."),
29         'state_open': fields.boolean('Open Backlog', help="Change the state of product backlogs to open if its in draft state"),
30         'convert_to_task': fields.boolean('Convert To Task', help="Create Task for Product Backlog")
31     }
32     _defaults = {
33          'state_open': True,
34          'convert_to_task': True,
35     }
36
37     def assign_sprint(self, cr, uid, ids, context=None):
38         backlog_obj = self.pool.get('project.scrum.product.backlog')
39         sprint_obj = self.pool.get('project.scrum.sprint')
40         task = self.pool.get('project.task')
41         backlog_ids = []
42         if context is None:
43             context = {}
44         data = self.browse(cr, uid, ids,context=context)[0]
45         for backlog in backlog_obj.browse(cr, uid, context['active_ids'], context=context):
46             backlog_ids.append(backlog.id)
47             if data.convert_to_task:
48                 task_id = task.create(cr, uid, {
49                     'product_backlog_id': backlog.id,
50                     'name': backlog.name,
51                     'description': backlog.note,
52                     'project_id': backlog.project_id.id,
53                     'user_id': False,
54                     'planned_hours':backlog.expected_hours,
55                     'remaining_hours':backlog.expected_hours,
56                 })
57                 message = _("Product Backlog '%s' is converted into Task %d.")  %(backlog.name, task_id)
58                 self.log(cr, uid, backlog.id, message)
59             if data.state_open and backlog.state == "draft":
60                 backlog_obj.write(cr, uid, backlog.id, {'state':'open'})
61             sprint = sprint_obj.browse(cr, uid, data.sprint_id.id, context=context)
62             message = _("Product Backlog '%s' is assigned to sprint %s") %(backlog.name, sprint.name)
63             self.log(cr, uid, backlog.id, message)
64         backlog_obj.write(cr, uid, backlog_ids, {'sprint_id': data.sprint_id.id}, context=context)
65         return {'type': 'ir.actions.act_window_close'}
66
67 backlog_sprint_assign()
68
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: