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 = ['mailgate.thread','project.task']
31 'message_ids': fields.one2many('mailgate.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 mailgate_obj = self.pool.get('email.server.tools')
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 = mailgate_obj.get_partner(cr, uid, msg_from)
55 res = self.create(cr, uid, data)
57 attachments = msg.get('attachments', [])
58 for attachment in attachments or []:
61 'datas':binascii.b2a_base64(str(attachments.get(attachment))),
62 'datas_fname': attachment,
63 'description': 'Mail attachment',
64 'res_model': self._name,
67 self.pool.get('ir.attachment').create(cr, uid, data_attach)
71 def message_update(self, cr, uid, id, msg, data={}, default_act='pending'):
72 mailgate_obj = self.pool.get('email.server.tools')
73 msg_actions, body_data = mailgate_obj.msg_act_get(msg)
75 'description': body_data,
77 act = 'do_'+default_act
78 if 'state' in msg_actions:
79 if msg_actions['state'] in ['draft','close','cancel','open','pending']:
80 act = 'do_' + msg_actions['state']
82 for k1,k2 in [('cost','planned_hours')]:
84 data[k2] = float(msg_actions[k1])
88 if 'priority' in msg_actions:
89 if msg_actions['priority'] in ('1','2','3','4','5'):
90 data['priority'] = msg_actions['priority']
92 self.write(cr, uid, [id], data)
93 getattr(self,act)(cr, uid, [id])
96 def message_followers(self, cr, uid, ids, context=None):
98 if isinstance(ids, (str, int, long)):
102 for task in self.browse(cr, uid, select):
103 user_email = (task.user_id and task.user_id.address_id and task.user_id.address_id.email) or False
104 res += [(user_email, False, False, task.priority)]
105 if isinstance(ids, (str, int, long)):
106 return len(res) and res[0] or False
109 def msg_send(self, cr, uid, id, *args, **argv):
112 def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context={}):
113 mailgate_pool = self.pool.get('mailgate.thread')
114 return mailgate_pool.history(cr, uid, cases, keyword, history=history,\
115 subject=subject, email=email, \
116 details=details, email_from=email_from,\
117 message_id=message_id, attach=attach, \
120 def do_draft(self, cr, uid, ids, *args, **kwargs):
121 res = super(project_tasks, self).do_draft(cr, uid, ids, *args, **kwargs)
122 tasks = self.browse(cr, uid, ids)
123 self._history(cr, uid, tasks, _('Draft'))
126 def do_open(self, cr, uid, ids, *args, **kwargs):
127 res = super(project_tasks, self).do_open(cr, uid, ids, *args, **kwargs)
128 tasks = self.browse(cr, uid, ids)
129 self._history(cr, uid, tasks, _('Open'))
132 def do_pending(self, cr, uid, ids, *args, **kwargs):
133 res = super(project_tasks, self).do_pending(cr, uid, ids, *args, **kwargs)
134 tasks = self.browse(cr, uid, ids)
135 self._history(cr, uid, tasks, _('Pending'))
138 def do_close(self, cr, uid, ids, *args, **kwargs):
139 res = super(project_tasks, self).do_close(cr, uid, ids, *args, **kwargs)
140 tasks = self.browse(cr, uid, ids)
142 if task.state == 'done':
143 self._history(cr, uid, tasks, _('Done'))
146 def do_cancel(self, cr, uid, ids, *args, **kwargs):
147 res = super(project_tasks, self).do_cancel(cr, uid, ids, *args, **kwargs)
148 tasks = self.browse(cr, uid, ids)
149 self._history(cr, uid, tasks, _('Cancel'))
153 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: