From e82bae3c66b772ae2b28349b23c30d309b26d7f0 Mon Sep 17 00:00:00 2001 From: Harshad Modi Date: Fri, 12 Sep 2008 15:55:46 +0530 Subject: [PATCH] fixed bugs : template system of project bzr revid: hmo@tinyerp.com-20080912102546-9bwelh0719kawlpg --- addons/project/project.py | 39 +++++++++++++++++++-------------- addons/project/project_view.xml | 6 ++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index 7ddca9ec22b..5f7ba9c0930 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -149,37 +149,42 @@ class project(osv.osv): ] # toggle activity of projects, their sub projects and their tasks - def settemplate(self, cr, uid, ids, context={}): + def set_template(self, cr, uid, ids, context={}): res = self.setActive(cr, uid, ids, value=False, context=context) return res - def resetproject(self, cr, uid, ids, context={}): + def reset_project(self, cr, uid, ids, context={}): res = self.setActive(cr, uid, ids,value=True, context=context) return res - def duplicatetemplate(self, cr, uid, ids, context={}): - proj = self.browse(cr, uid, ids[0], context) - self.pool.get('project.project').copy(cr, uid, ids[0],default={'state':'template'}, context=context) - cr.execute('select id from project_task where project_id=%d', (proj.id,)) - res = cr.fetchall() - tasks_ids = [x[0] for x in res] - if tasks_ids: - for i in tasks_ids: - self.pool.get('project.task').copy(cr, uid, i,default={'active':False}, context=context) - project_ids = [x[0] for x in 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':'template','parent_id':parent_id}) + cr.execute('select id from project_task where project_id=%d', (proj.id,)) + res = cr.fetchall() + tasks_ids = [x[0] for x in res] + for tasks_id in tasks_ids: + self.pool.get('project.task').copy(cr, uid, tasks_id,default={'project_id':new_id,'active':False}, context=context) + cr.execute('select id from project_project where parent_id=%d', (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}) return True # set active value for a project, its sub projects and its tasks def setActive(self, cr, uid, ids, value=True, context={}): - - for proj in self.browse(cr, uid, ids, context): + for proj in self.browse(cr, uid, ids, context): self.write(cr, uid, [proj.id], {'state': value and 'open' or 'template'}, context) cr.execute('select id from project_task where project_id=%d', (proj.id,)) - res = cr.fetchall() - tasks_id = [x[0] for x in res] + tasks_id = [x[0] for x in cr.fetchall()] if tasks_id: self.pool.get('project.task').write(cr, uid, tasks_id, {'active': value}, context) - project_ids = [x[0] for x in res] + cr.execute('select id from project_project where parent_id=%d', (proj.id,)) + project_ids = [x[0] for x in cr.fetchall()] + for child in project_ids: + self.setActive(cr, uid, [child], value, context) return True project() diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index 95cc72d9bb4..fad26416d78 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -32,9 +32,9 @@ -