From 853789d0aaea956e677af869ad9336af0b7fcfc3 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 5 May 2009 23:14:47 +0200 Subject: [PATCH] bugfixes bzr revid: fp@tinyerp.com-20090505211447-1cbbmt92q52u0hcq --- addons/project/project.py | 28 +++++++++++----------------- addons/project/project_view.xml | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index e180bf92a1b..e1af9e8293a 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -156,26 +156,20 @@ class project(osv.osv): return res def copy(self, cr, uid, id, default={},context={}): + proj = self.browse(cr, uid, id, context=context) default = default or {} - default['child_id'] = [] - return super(project, self).copy(cr, uid, id, default, context) + context['active_test'] = False + default['state'] = 'open' + default['name'] = proj.name+_(' (copy)') + res = super(project, self).copy(cr, uid, id, default, context) + ids = self.search(cr, uid, [('parent_id','child_of', [res])]) + cr.execute('update project_task set active=True where project_id in ('+','.join(map(str,ids))+')') + return res def duplicate_template(self, cr, uid, ids,context={}): - for proj in self.browse(cr, uid, ids): - parent_id=context.get('parent_id',False) - new_id=self.pool.get('project.project').copy(cr, uid, proj.id,default={'name':proj.name+_(' (copy)'),'state':'open','parent_id':parent_id}) - cr.execute('select id from project_task where project_id=%s', (proj.id,)) - res = cr.fetchall() - for (tasks_id,) in res: - self.pool.get('project.task').copy(cr, uid, tasks_id,default={'project_id':new_id,'active':True}, context=context) - cr.execute('select id from project_project where parent_id=%s', (proj.id,)) - res = cr.fetchall() - project_ids = [x[0] for x in res] - for child in project_ids: - self.duplicate_template(cr, uid, [child],context={'parent_id':new_id}) - - # TODO : Improve this to open the new project (using a wizard) - + default = {'parent_id': context.get('parent_id',False)} + for id in ids: + self.copy(cr, uid, id, default=default) cr.commit() raise osv.except_osv(_('Operation Done'), _('A new project has been created !\nWe suggest you to close this one and work on this new project.')) diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index 1e10a534ece..2784a0780bc 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -512,7 +512,7 @@ form tree,form,calendar,graph,gantt [('project_id', 'child_of', [active_id])] - {'project_id':active_id} + {'project_id':active_id, 'active_test':False}