diff options
Diffstat (limited to 'addons/project/wizard/project_close_task.py')
| -rw-r--r-- | addons/project/wizard/project_close_task.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/addons/project/wizard/project_close_task.py b/addons/project/wizard/project_close_task.py index b1cd933a4f7..715e70e59d0 100644 --- a/addons/project/wizard/project_close_task.py +++ b/addons/project/wizard/project_close_task.py @@ -19,8 +19,9 @@ # ############################################################################## -from osv import fields, osv +import time +from osv import fields, osv from tools.translate import _ from tools import email_send as email @@ -42,7 +43,7 @@ class project_close_task(osv.osv_memory): if 'task_id' in context: task = self.pool.get('project.task').browse(cr, uid, context['task_id']) partner_id = task.partner_id or task.project_id.partner_id - if partner_id and partner_id.address[0].email: + if partner_id and len(partner_id.address) and partner_id.address[0].email: email = partner_id.address[0].email return email @@ -54,10 +55,15 @@ class project_close_task(osv.osv_memory): return task.description or task.name return '' - _defaults={ + _defaults = { 'email': _get_email, 'description': _get_desc, } + + def close(self, cr, uid, ids, context=None): + if 'task_id' in context: + self.pool.get('project.task').write(cr, uid, [context['task_id']], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0}) + return {} def confirm(self, cr, uid, ids, context=None): if context is None: @@ -67,8 +73,10 @@ class project_close_task(osv.osv_memory): close_task = self.read(cr, uid, ids[0], []) to_adr = close_task['email'] description = close_task['description'] + if 'task_id' in context: - for task in self.pool.get('project.task').browse(cr, uid, [context['task_id']], context=context): + task_obj = self.pool.get('project.task') + for task in task_obj.browse(cr, uid, [context['task_id']], context=context): project = task.project_id subject = "Task '%s' closed" % task.name if task.user_id and task.user_id.address_id and task.user_id.address_id.email: @@ -89,9 +97,11 @@ class project_close_task(osv.osv_memory): footer = (project.warn_footer or '') % val body = u'%s\n%s\n%s\n\n-- \n%s' % (header, description, footer, signature) email(from_adr, [to_adr], subject, body.encode('utf-8'), email_bcc=[from_adr]) + task_obj.write(cr, uid, [task.id], {'state': 'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S'), 'remaining_hours': 0.0}) else: - raise osv.except_osv(_('Error'), _("Couldn't send mail because the contact for this task (%s) has no email address!") % contact.name) + raise osv.except_osv(_('Error'), _("Please specify the email address of partner.")) return {} project_close_task() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
