~nicolariolini/micronaet-addons-private/trunk

« back to all changes in this revision

Viewing changes to task_manager/task_manager.py

  • Committer: nicolariolini
  • Date: 2014-07-14 16:44:06 UTC
  • Revision ID: nicola.riolini@gmail.com-20140714164406-wzkpogk89vtxjqbu
Work in progress per il fetchmail

Show diffs side-by-side

added added

removed removed

Lines of Context:
423
423
    }
424
424
 
425
425
class task_activity_message(osv.osv):
426
 
    ''' Task activity message
 
426
    ''' Task activity message        
427
427
    '''
428
428
    _name = 'task.activity.message'
429
429
    _description = 'Task activity message'
430
430
 
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
 
433
        ''' 
 
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']
 
441
                },)# context)            
 
442
        except: # not a task ID message
 
443
            # Create new task and link there the message
 
444
            pass # TODO gestire bene l'errore            
 
445
        return True
 
446
        
 
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"
433
450
        '''
434
451
        #TODO debug #['body', 'from', 'attachments', 'cc', 'email_from', 'to', 'date', 'author_id', 'type', 'message_id', 'subject']
435
 
        try:
 
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
440
 
            return False
 
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']
 
462
            #    }, context)            
 
463
            return False #True
441
464
        
 
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,
448
 
            #state
449
472
            }, context=context)
450
473
        
451
474
        return True