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 ##############################################################################
23 from osv import fields, osv
24 from tools.translate import _
27 class project_tasks(osv.osv):
28 _inherit = 'project.task'
30 def message_new(self, cr, uid, msg, custom_values=None, context=None):
31 """ Overrides mail_thread message_new that is called by the mailgateway
32 through message_process.
33 This override updates the document according to the email.
35 if custom_values is None: custom_values = {}
36 custom_values.update({
39 'subject': msg.get('subject'),
41 custom_values.update(self.message_partner_by_email(cr, uid, msg.get('from', False), context=context))
42 return super(project_tasks,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
44 def message_update(self, cr, uid, ids, msg, update_vals=None, context=None):
45 """ Overrides mail_thread message_update that is called by the mailgateway
46 through message_process.
47 This method updates the task according to the email.
49 if update_vals is None: update_vals = {}
52 'cost':'planned_hours',
54 for line in msg['body_text'].split('\n'):
56 res = tools.misc.command_re.match(line)
58 match = res.group(1).lower()
59 field = maps.get(match)
62 update_vals[field] = float(res.group(2).lower())
63 except (ValueError, TypeError):
65 elif match.lower() == 'state' \
66 and res.group(2).lower() in ['cancel','close','draft','open','pending']:
67 act = 'do_%s' % res.group(2).lower()
69 getattr(self,act)(cr, uid, ids, context=context)
70 return super(project_tasks,self).message_update(cr, uid, msg, update_vals=update_vals, context=context)
72 def message_thread_followers(self, cr, uid, ids, context=None):
73 followers = super(project_tasks,self).message_thread_followers(cr, uid, ids, context=context)
74 for task in self.browse(cr, uid, followers.keys(), context=context):
75 task_followers = set(followers[task.id])
76 task_followers.add(task.user_id.email)
77 followers[task.id] = filter(None, task_followers)
81 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: