From ec181361f08933f8a6b15e8b5f6fe71c910c52c8 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 2 Sep 2015 11:20:53 +0200 Subject: [PATCH] [IMP] project, project_issue: discard project templates --- addons/project/project.py | 36 ++++++++--------------- addons/project/tests/test_project_flow.py | 27 ++++------------- addons/project_issue/project_issue.py | 9 ++++++ 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index 29d95405ffc..79feb43854b 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -177,8 +177,7 @@ class project(osv.osv): "- Employees Only: employees see all tasks or issues\n" "- Followers Only: employees see only the followed tasks or issues; if portal\n" " is activated, portal users see the followed tasks or issues."), - 'state': fields.selection([('template', 'Template'), - ('draft','New'), + 'state': fields.selection([('draft','New'), ('open','In Progress'), ('cancelled', 'Cancelled'), ('pending','Pending'), @@ -296,16 +295,10 @@ class project(osv.osv): 'search_view_id': search_view['res_id'], } - # set active value for a project, its sub projects and its tasks - def setActive(self, cr, uid, ids, value=True, context=None): - task_obj = self.pool.get('project.task') - for proj in self.browse(cr, uid, ids, context=None): - self.write(cr, uid, [proj.id], {'state': value and 'open' or 'template'}, context) - cr.execute('select id from project_task where project_id=%s', (proj.id,)) - tasks_id = [x[0] for x in cr.fetchall()] - if tasks_id: - task_obj.write(cr, uid, tasks_id, {'active': value}, context=context) - return True + @api.multi + def setActive(self, value=True): + """ Set a project as active/inactive, and its tasks as well. """ + self.write({'active': value}) def create(self, cr, uid, vals, context=None): if context is None: @@ -330,7 +323,13 @@ class project(osv.osv): if vals.get('alias_model'): model_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', vals.get('alias_model', 'project.task'))]) vals.update(alias_model_id=model_ids[0]) - return super(project, self).write(cr, uid, ids, vals, context=context) + res = super(project, self).write(cr, uid, ids, vals, context=context) + if 'active' in vals: + # archiving/unarchiving a project does it on its tasks, too + projects = self.browse(cr, uid, ids, context) + tasks = projects.with_context(active_test=False).mapped('tasks') + tasks.write({'active': vals['active']}) + return res class task(osv.osv): @@ -419,15 +418,6 @@ class task(osv.osv): default['name'] = _("%s (copy)") % current.name return super(task, self).copy_data(cr, uid, id, default, context) - def _is_template(self, cr, uid, ids, field_name, arg, context=None): - res = {} - for task in self.browse(cr, uid, ids, context=context): - res[task.id] = True - if task.project_id: - if task.project_id.active == False or task.project_id.state == 'template': - res[task.id] = False - return res - def _compute_displayed_image(self, cr, uid, ids, prop, arg, context=None): res = {} for line in self.browse(cr, uid, ids, context=context): @@ -435,7 +425,7 @@ class task(osv.osv): return res _columns = { - 'active': fields.function(_is_template, store=True, string='Not a Template Task', type='boolean', help="This field is computed automatically and have the same behavior than the boolean 'active' field: if the task is linked to a template or unactivated project, it will be hidden unless specifically asked."), + 'active': fields.boolean('Active'), 'name': fields.char('Task Title', track_visibility='onchange', size=128, required=True, select=True), 'description': fields.html('Description'), 'priority': fields.selection([('0','Normal'), ('1','High')], 'Priority', select=True), diff --git a/addons/project/tests/test_project_flow.py b/addons/project/tests/test_project_flow.py index 77615c5a4df..04048a74441 100644 --- a/addons/project/tests/test_project_flow.py +++ b/addons/project/tests/test_project_flow.py @@ -34,26 +34,11 @@ Integrator at Agrolait""" class TestProjectFlow(TestProjectBase): - @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models') - def test_project_process_project_user(self): - self.assertRaises(AccessError, self.project_pigs.sudo(self.user_projectuser).set_template) - - def test_project_process_project_manager_set_template(self): - pigs = self.project_pigs.sudo(self.user_projectmanager) - pigs.set_template() - self.assertEqual(pigs.state, 'template') - self.assertEqual(len(pigs.tasks), 0, 'project: set_template: project tasks should have been set inactive') - - # pigs.reset_project() - # self.assertEqual(pigs.state, 'open') - # self.assertEqual(len(pigs.tasks), 2, 'project: reset_project: project tasks should have been set active') - def test_project_process_project_manager_duplicate(self): pigs = self.project_pigs.sudo(self.user_projectmanager) - new_template_act = pigs.duplicate_template() - new_project = self.env['project.project'].sudo(self.user_projectmanager).browse(new_template_act['res_id']) - self.assertEqual(new_project.state, 'open') - self.assertEqual(len(new_project.tasks), 2, 'project: duplicating a project template should duplicate its tasks') + dogs = pigs.copy() + self.assertEqual(dogs.state, 'open') + self.assertEqual(len(dogs.tasks), 2, 'project: duplicating a project must duplicate its tasks') def test_project_process_project_manager_state(self): pigs = self.project_pigs.sudo(self.user_projectmanager) @@ -67,11 +52,9 @@ class TestProjectFlow(TestProjectBase): self.assertEqual(pigs.state, 'close') # Re-open pigs.state = 'open' - # Re-convert into a template - pigs.set_template() # Copy the project - new_project = pigs.copy() - self.assertEqual(len(new_project.tasks), 2, 'project: copied project should have copied task') + dogs = pigs.copy() + self.assertEqual(len(dogs.tasks), 2, 'project: copied project should have copied task') # Cancel the project pigs.state = 'cancelled' self.assertEqual(pigs.state, 'cancelled', 'project: cancelled project should be in cancel state') diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index 92eb06c7b66..2d34e9f36b9 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -439,6 +439,15 @@ class project(osv.Model): domain=[('stage_id.fold', '=', False)]), } + @api.multi + def write(self, vals): + res = super(project, self).write(vals) + if 'active' in vals: + # archiving/unarchiving a project does it on its issues, too + issues = self.with_context(active_test=False).mapped('issue_ids') + issues.write({'active': vals['active']}) + return res + class account_analytic_account(osv.Model): _inherit = 'account.analytic.account'