1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
24 from tools.translate import _
25 from tools import email_send as email
27 class project_close_task(osv.osv_memory):
32 _description = "Project Close Task"
34 'email': fields.char('E-Mail', size=64, help="Email Address"),
35 'description': fields.text('Description'),
38 def _get_email(self, cr, uid, context=None):
42 if 'task_id' in context:
43 task = self.pool.get('project.task').browse(cr, uid, context['task_id'])
44 partner_id = task.partner_id or task.project_id.partner_id
45 if partner_id and partner_id.address[0].email:
46 email = partner_id.address[0].email
49 def _get_desc(self, cr, uid, context=None):
52 if 'task_id' in context:
53 task = self.pool.get('project.task').browse(cr, uid, context['task_id'])
54 return task.description or task.name
59 'description': _get_desc,
62 def confirm(self, cr, uid, ids, context=None):
65 if not 'task_id' in context:
67 close_task = self.read(cr, uid, ids[0], [])
68 to_adr = close_task['email']
69 description = close_task['description']
70 if 'task_id' in context:
71 for task in self.pool.get('project.task').browse(cr, uid, [context['task_id']], context=context):
72 project = task.project_id
73 subject = "Task '%s' closed" % task.name
74 if task.user_id and task.user_id.address_id and task.user_id.address_id.email:
75 from_adr = task.user_id.address_id.email
76 signature = task.user_id.signature
78 raise osv.except_osv(_('Error'), _("Couldn't send mail because your email address is not configured!"))
82 'user_id': task.user_id.name,
83 'task_id': "%d/%d" % (project.id, task.id),
84 'date_start': task.date_start,
85 'date_end': task.date_end,
88 header = (project.warn_header or '') % val
89 footer = (project.warn_footer or '') % val
90 body = u'%s\n%s\n%s\n\n-- \n%s' % (header, description, footer, signature)
91 email(from_adr, [to_adr], subject, body.encode('utf-8'), email_bcc=[from_adr])
93 raise osv.except_osv(_('Error'), _("Couldn't send mail because the contact for this task (%s) has no email address!") % contact.name)
97 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: