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
23 from tools.translate import _
28 class project_tasks(osv.osv):
29 _name = "project.task"
30 _inherit = ['mail.thread','project.task']
33 'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)], readonly=True),
36 def message_new(self, cr, uid, msg, custom_values=None, context=None):
37 res_id = super(project_tasks,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
38 subject = msg.get('subject')
39 body = msg.get('body_text')
40 msg_from = msg.get('from')
46 data.update(self.message_partner_by_email(cr, uid, msg_from))
47 self.write(cr, uid, [res_id], data, context)
50 def message_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
52 'description': msg['body_text'],
54 act = 'do_'+default_act
57 'cost':'planned_hours',
59 for line in msg['body_text'].split('\n'):
61 res = tools.misc.command_re.match(line)
63 match = res.group(1).lower()
64 field = maps.get(match)
67 data[field] = float(res.group(2).lower())
68 except (ValueError, TypeError):
70 elif match.lower() == 'state' \
71 and res.group(2).lower() in ['cancel','close','draft','open','pending']:
72 act = 'do_%s' % res.group(2).lower()
74 self.write(cr, uid, ids, data, context=context)
75 getattr(self,act)(cr, uid, ids, context=context)
76 self.message_append_dict(cr, uid, [res_id], msg, context=context)
79 def message_thread_followers(self, cr, uid, ids, context=None):
80 followers = super(project_tasks,self).message_thread_followers(cr, uid, ids, context=context)
81 for task in self.browse(cr, uid, followers.keys(), context=context):
82 task_followers = set(followers[task.id])
83 task_followers.add(task.user_id.user_email)
84 followers[task.id] = filter(None, task_followers)
87 def do_draft(self, cr, uid, ids, context=None):
88 res = super(project_tasks, self).do_draft(cr, uid, ids, context)
89 tasks = self.browse(cr, uid, ids, context=context)
90 self.message_append(cr, uid, tasks, _('Draft'), context=context)
93 def do_open(self, cr, uid, ids, context=None):
94 res = super(project_tasks, self).do_open(cr, uid, ids, context)
95 tasks = self.browse(cr, uid, ids, context=context)
96 self.message_append(cr, uid, tasks, _('Open'), context=context)
99 def do_pending(self, cr, uid, ids, context=None):
100 res = super(project_tasks, self).do_pending(cr, uid, ids, context)
101 tasks = self.browse(cr, uid, ids, context=context)
102 self.message_append(cr, uid, tasks, _('Pending'), context=context)
105 def do_close(self, cr, uid, ids, context=None):
106 res = super(project_tasks, self).do_close(cr, uid, ids, context)
107 tasks = self.browse(cr, uid, ids, context=context)
109 if task.state == 'done':
110 self.message_append(cr, uid, tasks, _('Done'), context=context)
113 def do_cancel(self, cr, uid, ids, context=None):
114 res = super(project_tasks, self).do_cancel(cr, uid, ids, context=context)
115 tasks = self.browse(cr, uid, ids, context=context)
116 self.message_append(cr, uid, tasks, _('Cancel'), context=context)
120 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: