1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
21 from osv import osv, fields
23 class backlog_create_task(osv.osv_memory):
24 _name = 'project.scrum.backlog.create.task'
25 _description = 'Create Tasks from Product Backlogs'
27 'user_id': fields.many2one('res.users', 'Assign To', help="Responsible user who can work on task")
30 def do_create(self, cr, uid, ids, context=None):
31 mod_obj = self.pool.get('ir.model.data')
32 task = self.pool.get('project.task')
33 backlog_id = self.pool.get('project.scrum.product.backlog')
34 document_pool = self.pool.get('ir.attachment')
37 data = self.read(cr, uid, ids, [], context=context)[0]
38 data['user_id'] = data['user_id'][0]
40 backlogs = backlog_id.browse(cr, uid, context['active_ids'], context=context)
41 result = mod_obj._get_id(cr, uid, 'project', 'view_task_search_form')
42 id = mod_obj.read(cr, uid, result, ['res_id'])
44 for backlog in backlogs:
45 task_id = task.create(cr, uid, {
46 'product_backlog_id': backlog.id,
48 'description': backlog.note,
49 'project_id': backlog.project_id.id,
50 'user_id': data['user_id'] or False,
51 'planned_hours': backlog.expected_hours,
52 'remaining_hours':backlog.expected_hours,
53 'sequence':backlog.sequence,
55 document_ids = document_pool.search(cr, uid, [('res_id', '=', backlog.id), ('res_model', '=', backlog_id._name)])
56 for document_id in document_ids:
57 document_pool.copy(cr, uid, document_id, default={'res_id':task_id, 'res_model':task._name})
58 ids_task.append(task_id)
60 'domain': "[('product_backlog_id','in',["+','.join(map(str, context['active_ids']))+"])]",
64 'view_mode': 'tree,form',
65 'res_model': 'project.task',
67 'type': 'ir.actions.act_window',
68 'search_view_id': id['res_id'],
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: