425
425
class task_activity_message(osv.osv):
426
''' Task activity message
426
''' Task activity message
428
428
_name = 'task.activity.message'
429
429
_description = 'Task activity message'
431
def message_new(self, cr, user_id, msg, custom_values, context=None):
431
def message_post(self, cr, uid, ids, **kwargs):
432
''' Raise event when fetch mail
434
#import pdb; pdb.set_trace()
435
#kwargs['body'].split("[[")[1].split("]]")[0].replace("<br>", "").replace("\n","").replace(" ", " ")
436
try: # If message is linked to task, subj: subject [[TASK#1]]
437
task_pool = self.pool.get("task.activity")
438
task_id = task_pool.create(cr, uid, {
439
'name': kwargs['subject'],
440
#'user_id', msg['email_from']
442
except: # not a task ID message
443
# Create new task and link there the message
444
pass # TODO gestire bene l'errore
447
def message_new(self, cr, uid, msg, custom_values, context=None):
432
448
''' Try to identificate task and create new message or WF actions
449
Subject must parsed as: "task [[TASK#1]] subject"
434
451
#TODO debug #['body', 'from', 'attachments', 'cc', 'email_from', 'to', 'date', 'author_id', 'type', 'message_id', 'subject']
452
try: # If message is linked to task, subj: subject [[TASK#1]]
436
453
msg_part = msg['subject'].split("[[")[1]
437
454
msg_part = msg_part.split("]]")[0]
438
455
task_id = int(msg_part.split("#")[1])
439
456
except: # not a task ID message
457
# Create new task with message:
458
#task_pool = self.pool.get("task.activity")
459
#task_id = task_pool.create(cr, uid, {
460
# 'name': msg['subject'],
461
# #'user_id', msg['email_from']
465
# TODO verificare cosa fa questa parte!!!
442
466
self.create(cr, uid, {
443
467
'name': msg['subject'],
444
468
'date': datetime.now().strftime(DEFAULT_SERVER_DATE_FORMAT),
445
469
'user_id': SUPERUSER_ID, # Search uid from mail msg['from'],
446
470
'note': msg['body'],
447
471
'task_id': task_id,
449
472
}, context=context)