[IMP] account: unique description for wizard model
[odoo/odoo.git] / addons / project_scrum / wizard / project_scrum_backlog_merger.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 project_scrum_backlog_merge(osv.osv_memory):
25     _name = 'project.scrum.backlog.merge'
26     _description = 'Merge Product Backlogs'
27     _columns = {
28         'project_id': fields.many2one('project.project', 'Project', help="Select project for the new product backlog"),
29     }
30
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')
34         p_list = []
35         if context is None:
36             context = {}
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)
43
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']
49             return {
50                 'context': context,
51                 'view_type': 'form',
52                 'view_mode': 'form',
53                 'res_model': 'project.scrum.backlog.merge',
54                 'views': [(resource_id,'form')],
55                 'type': 'ir.actions.act_window',
56                 'target': 'new',
57             }
58         return self.do_merge(cr, uid, ids, context=context)
59
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')
63         task_lines = []
64         new_exp_hour = []
65         if context is None:
66             context = {}
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
73         else:
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
77         new_note = ''
78         new_description = ''
79         for backlogs in backlog_obj.browse(cr, uid, context['active_ids'], context=context):
80             if new_note:
81                 new_note += ' + '
82                 new_description += '\n\n'+('-'*50)+'\n'
83             new_note += backlogs.name
84             new_description += (backlogs.name or '') + '\n' + (backlogs.note or '')
85
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, {
90             'name': new_note,
91             'note': new_description,
92             'project_id': new_project_id,
93             'expected_hours': round(max(new_exp_hour))
94         }, context=context)
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'}
99
100 project_scrum_backlog_merge()
101 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: