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
22 from tools.translate import _
24 class project_scrum_backlog_merge(osv.osv_memory):
25 _name = 'project.scrum.backlog.merge'
26 _description = 'Merge Product Backlogs'
28 'project_id': fields.many2one('project.project', 'Project', help="Select project for the new product backlog"),
31 def check_backlogs(self, cr, uid, ids, context=None):
32 backlog_obj = self.pool.get('project.scrum.product.backlog')
33 mod_obj = self.pool.get('ir.model.data')
37 #If only one product backlog selected for merging then show an exception
38 if len(context['active_ids']) < 2:
39 raise osv.except_osv(_('Warning'),_('Please select at least two product Backlogs'))
40 #If any of the backlog state is done then it will show an exception
41 for backlogs in backlog_obj.browse(cr, uid, context['active_ids'], context=context):
42 p_list.append(backlogs.project_id.id)
44 #For checking whether project id's are different or same.
45 if len(set(p_list)) != 1:
46 context.update({'scrum_projects': True})
47 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','scrum_merge_project_id_view')], context=context)
48 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
53 'res_model': 'project.scrum.backlog.merge',
54 'views': [(resource_id,'form')],
55 'type': 'ir.actions.act_window',
58 return self.do_merge(cr, uid, ids, context=context)
60 def do_merge(self, cr, uid, ids, context=None):
61 backlog_obj = self.pool.get('project.scrum.product.backlog')
62 task_obj = self.pool.get('project.task')
67 #This will check product backlog's project id if different then will accept a new id provided by the user.
68 if 'scrum_projects' in context:
69 data = self.browse(cr, uid, ids, [])[0]
70 if data.project_id.id == False:
71 raise osv.except_osv(_('Warning'),_('Please select any Project.'))
72 new_project_id = data.project_id.id
74 p_id = backlog_obj.read(cr, uid, context['active_id'], ['project_id'])
75 new_project_id = p_id['project_id'][0]
76 #To merge note and description of backlogs
79 for backlogs in backlog_obj.browse(cr, uid, context['active_ids'], context=context):
82 new_description += '\n\n'+('-'*50)+'\n'
83 new_note += backlogs.name
84 new_description += (backlogs.name or '') + '\n' + (backlogs.note or '')
86 new_exp_hour.append(backlogs.expected_hours)
87 for line in backlogs.tasks_id:
88 task_lines.append(line.id)
89 id_b = backlog_obj.create(cr, uid, {
91 'note': new_description,
92 'project_id': new_project_id,
93 'expected_hours': round(max(new_exp_hour))
95 #To assing a new product backlog to merged tasks
96 task_obj.write(cr, uid, task_lines, {'product_backlog_id': id_b})
97 backlog_obj.unlink(cr, uid, context['active_ids'], context=context)
98 return {'type': 'ir.actions.act_window_close'}
100 project_scrum_backlog_merge()
101 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: