From 53dfea69f8539335a04eff5149422e4f164debbe Mon Sep 17 00:00:00 2001 From: Jigar Amin Date: Wed, 22 Jun 2011 11:49:23 +0530 Subject: [PATCH] [BUG/FIX] project : chid task has to be done before parent for scheduling the tasks bzr revid: jam@tinyerp.com-20110622061923-3lhjlc649ov2llqd --- addons/project/project.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index 072f7cc31c3..b1a8fddee3c 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -529,8 +529,6 @@ class task(osv.osv): # # Override view according to the company definition # - - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): users_obj = self.pool.get('res.users') @@ -562,13 +560,27 @@ class task(osv.osv): res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours',tm) return res + def _check_child_task(self, cr, uid, ids, context=None): + if context == None: + context = {} + tasks = self.browse(cr, uid, ids, context=context) + for task in tasks: + if task.child_ids: + for child in task.child_ids: + if child.state in ['draft', 'open', 'pending']: + raise osv.except_osv(_("Warning !"), _("Child task still open.\nPlease cancel or complete child task first.")) + return True + def action_close(self, cr, uid, ids, context=None): # This action open wizard to send email to partner or project manager after close task. - project_id = len(ids) and ids[0] or False - if not project_id: return False - task = self.browse(cr, uid, project_id, context=context) + if context == None: + context = {} + task_id = len(ids) and ids[0] or False + self._check_child_task(cr, uid, ids, context=context) + if not task_id: return False + task = self.browse(cr, uid, task_id, context=context) project = task.project_id - res = self.do_close(cr, uid, [project_id], context=context) + res = self.do_close(cr, uid, [task_id], context=context) if project.warn_manager or project.warn_customer: return { 'name': _('Send Email after close task'), @@ -643,6 +655,7 @@ class task(osv.osv): def do_cancel(self, cr, uid, ids, *args): request = self.pool.get('res.request') tasks = self.browse(cr, uid, ids) + self._check_child_task(cr, uid, ids, context=context) for task in tasks: project = task.project_id if project.warn_manager and project.user_id and (project.user_id.id != uid): @@ -736,13 +749,19 @@ class task(osv.osv): index = sorted_types.index(typeid) self.write(cr, uid, task.id, {'type_id': sorted_types[index+1]}) return True - + def next_type(self, cr, uid, ids, *args): return self._change_type(cr, uid, ids, True, *args) def prev_type(self, cr, uid, ids, *args): return self._change_type(cr, uid, ids, False, *args) - + + def unlink(self, cr, uid, ids, context=None): + if context == None: + context = {} + self._check_child_task(cr, uid, ids, context=context) + res = super(task, self).unlink(cr, uid, ids, context) + return res task()