fixed bugs : template system of project

bzr revid: hmo@tinyerp.com-20080912102546-9bwelh0719kawlpg
This commit is contained in:
Harshad Modi 2008-09-12 15:55:46 +05:30
parent 5c0ca471a2
commit e82bae3c66
2 changed files with 25 additions and 20 deletions

View File

@ -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()

View File

@ -32,9 +32,9 @@
<field colspan="4" name="members" nolabel="1"/>
<group col="6" colspan="8">
<field name="state"/>
<button name="settemplate" string="Set as Template" type="object" states="open"/>
<button name="resetproject" string="Reset as Project" type="object" states="template"/>
<button name="duplicatetemplate" string="Duplicate Template" type="object" states="template"/>
<button name="set_template" string="Set as Template" type="object" states="open"/>
<button name="reset_project" string="Reset as Project" type="object" states="template"/>
<button name="duplicate_template" string="Duplicate Template" type="object" states="template"/>
</group>
</page>
<page groups="base.group_extended" string="Partner Info">