diff --git a/addons/project/project.py b/addons/project/project.py index 0851be60e4d..e2eaf51baba 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -475,8 +475,20 @@ class task(osv.osv): ids = child_ids return True + def _check_dates(self, cr, uid, ids, context=None): + if context == None: + context = {} + obj_task = self.browse(cr, uid, ids[0], context=context) + start = obj_task.date_start or False + end = obj_task.date_end or False + if start and end : + if start > end: + return False + return True + _constraints = [ - (_check_recursion, 'Error ! You cannot create recursive tasks.', ['parent_ids']) + (_check_recursion, 'Error ! You cannot create recursive tasks.', ['parent_ids']), + (_check_dates, 'Error ! Task end-date must be greater then task start-date', ['date_start','date_end']) ] # # Override view according to the company definition @@ -540,6 +552,7 @@ class task(osv.osv): """ request = self.pool.get('res.request') for task in self.browse(cr, uid, ids, context=context): + vals = {} project = task.project_id if project: # Send request to project manager @@ -562,7 +575,11 @@ class task(osv.osv): reopen = False if reopen: self.do_reopen(cr, uid, [parent_id.id]) - self.write(cr, uid, [task.id], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0}) + vals.update({'state': 'done'}) + vals.update({'remaining_hours': 0.0}) + if not task.date_end: + vals.update({ 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')}) + self.write(cr, uid, [task.id],vals) message = _("The task '%s' is done") % (task.name,) self.log(cr, uid, task.id, message) return True