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 _
26 class project_tasks(osv.osv):
27 _name = "project.task"
28 _inherit = ['email.thread','project.task']
31 'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)], readonly=True),
33 def message_new(self, cr, uid, msg, context=None):
35 # Automatically calls when new email message arrives
37 # @param self: The object pointer
38 # @param cr: the current row, from the database cursor,
39 # @param uid: the current user’s ID for security checks
41 thread_obj = self.pool.get('email.thread')
42 subject = msg.get('subject')
43 body = msg.get('body')
44 msg_from = msg.get('from')
45 priority = msg.get('priority')
50 'planned_hours' : 0.0,
52 res = thread_obj.get_partner(cr, uid, msg_from)
55 res_id = self.create(cr, uid, vals, context)
57 attachments = msg.get('attachments', {})
58 self.history(cr, uid, [res_id], _('receive'), history=True,
59 subject = msg.get('subject'),
60 email = msg.get('to'),
61 details = msg.get('body'),
62 email_from = msg.get('from'),
63 email_cc = msg.get('cc'),
64 message_id = msg.get('message-id'),
65 references = msg.get('references', False) or msg.get('in-reply-to', False),
67 email_date = msg.get('date'),
72 def message_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
73 thread_obj = self.pool.get('email.thread')
74 msg_actions, body_data = thread_obj.msg_act_get(msg)
76 'description': body_data,
78 act = 'do_'+default_act
79 if 'state' in msg_actions:
80 if msg_actions['state'] in ['draft','close','cancel','open','pending']:
81 act = 'do_' + msg_actions['state']
83 for k1,k2 in [('cost','planned_hours')]:
85 data[k2] = float(msg_actions[k1])
89 if 'priority' in msg_actions:
90 if msg_actions['priority'] in ('1','2','3','4','5'):
91 data['priority'] = msg_actions['priority']
93 self.write(cr, uid, ids, data)
94 getattr(self,act)(cr, uid, ids)
96 attachments = msg.get('attachments', {})
97 self.history(cr, uid, ids, _('receive'), history=True,
98 subject = msg.get('subject'),
99 email = msg.get('to'),
100 details = msg.get('body'),
101 email_from = msg.get('from'),
102 email_cc = msg.get('cc'),
103 message_id = msg.get('message-id'),
104 references = msg.get('references', False) or msg.get('in-reply-to', False),
105 attach = attachments,
106 email_date = msg.get('date'),
110 def thread_followers(self, cr, uid, ids, context=None):
112 if isinstance(ids, (str, int, long)):
116 for task in self.browse(cr, uid, select, context=context):
117 user_email = (task.user_id and task.user_id.address_id and task.user_id.address_id.email) or False
118 res += [(user_email, False, False, task.priority)]
119 if isinstance(ids, (str, int, long)):
120 return len(res) and res[0] or False
123 def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None):
124 thread_pool = self.pool.get('email.thread')
125 return thread_pool.history(cr, uid, cases, keyword, history=history,\
126 subject=subject, email=email, \
127 details=details, email_from=email_from,\
128 message_id=message_id, attach=attach, \
131 def do_draft(self, cr, uid, ids, *args, **kwargs):
132 res = super(project_tasks, self).do_draft(cr, uid, ids, *args, **kwargs)
133 tasks = self.browse(cr, uid, ids)
134 self._history(cr, uid, tasks, _('Draft'))
137 def do_open(self, cr, uid, ids, *args, **kwargs):
138 res = super(project_tasks, self).do_open(cr, uid, ids, *args, **kwargs)
139 tasks = self.browse(cr, uid, ids)
140 self._history(cr, uid, tasks, _('Open'))
143 def do_pending(self, cr, uid, ids, *args, **kwargs):
144 res = super(project_tasks, self).do_pending(cr, uid, ids, *args, **kwargs)
145 tasks = self.browse(cr, uid, ids)
146 self._history(cr, uid, tasks, _('Pending'))
149 def do_close(self, cr, uid, ids, *args, **kwargs):
150 res = super(project_tasks, self).do_close(cr, uid, ids, *args, **kwargs)
151 tasks = self.browse(cr, uid, ids)
153 if task.state == 'done':
154 self._history(cr, uid, tasks, _('Done'))
157 def do_cancel(self, cr, uid, ids, *args, **kwargs):
158 res = super(project_tasks, self).do_cancel(cr, uid, ids, *args, **kwargs)
159 tasks = self.browse(cr, uid, ids)
160 self._history(cr, uid, tasks, _('Cancel'))
164 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: