2010-08-20 11:38:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2011-06-21 07:08:41 +00:00
|
|
|
from osv import fields, osv
|
2010-08-20 11:38:44 +00:00
|
|
|
from tools.translate import _
|
2011-08-09 23:44:28 +00:00
|
|
|
import tools
|
2010-08-20 11:38:44 +00:00
|
|
|
import binascii
|
|
|
|
|
2011-06-21 07:08:41 +00:00
|
|
|
|
2010-08-20 11:38:44 +00:00
|
|
|
class project_tasks(osv.osv):
|
|
|
|
_name = "project.task"
|
2011-08-09 23:44:28 +00:00
|
|
|
_inherit = ['mail.thread','project.task']
|
2011-02-07 05:51:57 +00:00
|
|
|
|
2010-08-20 11:38:44 +00:00
|
|
|
_columns={
|
2011-08-09 23:44:28 +00:00
|
|
|
'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)], readonly=True),
|
2010-08-20 11:38:44 +00:00
|
|
|
}
|
2011-06-21 07:08:41 +00:00
|
|
|
|
2011-08-22 17:16:59 +00:00
|
|
|
def message_new(self, cr, uid, msg, custom_values=None, context=None):
|
|
|
|
thread_obj = self.pool.get('mail.thread')
|
2010-08-20 11:38:44 +00:00
|
|
|
subject = msg.get('subject')
|
2011-08-22 17:16:59 +00:00
|
|
|
body = msg.get('body_text')
|
2010-08-20 11:38:44 +00:00
|
|
|
msg_from = msg.get('from')
|
|
|
|
|
2011-02-07 05:51:57 +00:00
|
|
|
data = {
|
2010-08-20 11:38:44 +00:00
|
|
|
'name': subject,
|
|
|
|
'description': body,
|
2011-06-21 07:08:41 +00:00
|
|
|
'planned_hours': 0.0,
|
2010-08-20 11:38:44 +00:00
|
|
|
}
|
2011-03-18 13:44:19 +00:00
|
|
|
res = thread_obj.get_partner(cr, uid, msg_from)
|
2010-08-20 11:38:44 +00:00
|
|
|
if res:
|
|
|
|
data.update(res)
|
2011-04-20 06:06:05 +00:00
|
|
|
|
2011-08-22 17:16:59 +00:00
|
|
|
if custom_values and isinstance(custom_values, dict):
|
|
|
|
data.update(custom_values)
|
|
|
|
res_id = self.create(cr, uid, data, context)
|
|
|
|
self.append_mail(cr, uid, [res_id], msg, context=context)
|
2011-04-20 06:06:05 +00:00
|
|
|
return res_id
|
2011-02-07 05:51:57 +00:00
|
|
|
|
2011-04-20 08:11:41 +00:00
|
|
|
def message_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
|
2010-08-20 11:38:44 +00:00
|
|
|
data.update({
|
2011-08-09 23:44:28 +00:00
|
|
|
'description': msg['body_text'],
|
2010-08-20 11:38:44 +00:00
|
|
|
})
|
|
|
|
act = 'do_'+default_act
|
|
|
|
|
2011-08-09 23:44:28 +00:00
|
|
|
maps = {
|
|
|
|
'cost':'planned_hours',
|
|
|
|
}
|
2011-08-22 17:16:59 +00:00
|
|
|
for line in msg['body_text'].split('\n'):
|
2011-08-09 23:44:28 +00:00
|
|
|
line = line.strip()
|
|
|
|
res = tools.misc.command_re.match(line)
|
|
|
|
if res:
|
|
|
|
match = res.group(1).lower()
|
|
|
|
field = maps.get(match)
|
|
|
|
if field:
|
|
|
|
try:
|
|
|
|
data[field] = float(res.group(2).lower())
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
pass
|
|
|
|
elif match.lower() == 'state' \
|
|
|
|
and res.group(2).lower() in ['cancel','close','draft','open','pending']:
|
|
|
|
act = 'do_%s' % res.group(2).lower()
|
|
|
|
|
|
|
|
self.write(cr, uid, ids, data, context=context)
|
|
|
|
getattr(self,act)(cr, uid, ids, context=context)
|
2011-08-22 17:16:59 +00:00
|
|
|
self.append_mail(cr, uid, [res_id], msg, context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
return True
|
|
|
|
|
2011-03-18 13:44:19 +00:00
|
|
|
def thread_followers(self, cr, uid, ids, context=None):
|
2010-08-20 11:38:44 +00:00
|
|
|
res = []
|
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
select = [ids]
|
|
|
|
else:
|
|
|
|
select = ids
|
2010-11-22 10:37:53 +00:00
|
|
|
for task in self.browse(cr, uid, select, context=context):
|
2011-07-28 06:11:56 +00:00
|
|
|
user_email = (task.user_id and task.user_id.user_email) or False
|
2010-08-20 11:38:44 +00:00
|
|
|
res += [(user_email, False, False, task.priority)]
|
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
return len(res) and res[0] or False
|
|
|
|
return res
|
|
|
|
|
|
|
|
def msg_send(self, cr, uid, id, *args, **argv):
|
|
|
|
return True
|
2011-06-21 07:08:41 +00:00
|
|
|
|
2011-06-29 08:32:22 +00:00
|
|
|
def do_draft(self, cr, uid, ids, context=None):
|
2011-06-21 07:08:41 +00:00
|
|
|
res = super(project_tasks, self).do_draft(cr, uid, ids, context)
|
|
|
|
tasks = self.browse(cr, uid, ids, context=context)
|
2011-08-09 23:44:28 +00:00
|
|
|
self.history(cr, uid, tasks, _('Draft'), context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
return res
|
2011-02-07 05:51:57 +00:00
|
|
|
|
2011-06-21 07:08:41 +00:00
|
|
|
def do_open(self, cr, uid, ids, context=None):
|
|
|
|
res = super(project_tasks, self).do_open(cr, uid, ids, context)
|
|
|
|
tasks = self.browse(cr, uid, ids, context=context)
|
2011-08-09 23:44:28 +00:00
|
|
|
self.history(cr, uid, tasks, _('Open'), context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
return res
|
2011-02-07 05:51:57 +00:00
|
|
|
|
2011-06-21 07:08:41 +00:00
|
|
|
def do_pending(self, cr, uid, ids, context=None):
|
|
|
|
res = super(project_tasks, self).do_pending(cr, uid, ids, context)
|
|
|
|
tasks = self.browse(cr, uid, ids, context=context)
|
2011-08-09 23:44:28 +00:00
|
|
|
self.history(cr, uid, tasks, _('Pending'), context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
return res
|
2011-02-07 05:51:57 +00:00
|
|
|
|
2011-06-21 07:08:41 +00:00
|
|
|
def do_close(self, cr, uid, ids, context=None):
|
|
|
|
res = super(project_tasks, self).do_close(cr, uid, ids, context)
|
|
|
|
tasks = self.browse(cr, uid, ids, context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
for task in tasks:
|
|
|
|
if task.state == 'done':
|
2011-08-09 23:44:28 +00:00
|
|
|
self.history(cr, uid, tasks, _('Done'), context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
return res
|
2011-02-07 05:51:57 +00:00
|
|
|
|
2011-06-21 07:08:41 +00:00
|
|
|
def do_cancel(self, cr, uid, ids, context=None):
|
|
|
|
res = super(project_tasks, self).do_cancel(cr, uid, ids, context=context)
|
|
|
|
tasks = self.browse(cr, uid, ids, context=context)
|
2011-08-09 23:44:28 +00:00
|
|
|
self.history(cr, uid, tasks, _('Cancel'), context=context)
|
2010-08-20 11:38:44 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
project_tasks()
|
2010-08-31 12:10:55 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|