~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to document_change/document_change_mailgate.py

  • Committer: Fabien Pinckaers
  • Date: 2010-01-29 01:04:21 UTC
  • Revision ID: fp@tinyerp.com-20100129010421-6wt4fmex3iecktp9
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
import time
 
23
import re
 
24
import os
 
25
 
 
26
import mx.DateTime
 
27
import base64
 
28
 
 
29
from tools.translate import _
 
30
 
 
31
import tools
 
32
from osv import fields,osv,orm
 
33
from osv.orm import except_orm
 
34
 
 
35
class document_file(osv.osv):    
 
36
    _inherit = "ir.attachment"
 
37
 
 
38
    _columns = {
 
39
        'email_notification_ids':fields.one2many('document.email.notes','document_id','Phase', readonly=True),       
 
40
    }    
 
41
 
 
42
    def msg_new(self, cr, uid, msg):
 
43
        raise Exception(_('Sorry, Not Allowed to create document'))                
 
44
        return False
 
45
    
 
46
    def msg_update(self, cr, uid, id, msg, data={}, default_act='pending'):         
 
47
        mailgate_obj = self.pool.get('mail.gateway')
 
48
        msg_actions, body_data = mailgate_obj.msg_act_get(msg) 
 
49
        email_notify_data = {
 
50
            'name' : msg['Subject'],
 
51
            'description' : body_data,
 
52
            'email' : msg['From'],            
 
53
        }          
 
54
        data.update({            
 
55
            'email_notification_ids': [(0, 0, email_notify_data)],
 
56
        })        
 
57
        res = self.write(cr, uid, [id], data)
 
58
        return res
 
59
 
 
60
    def emails_get(self, cr, uid, ids, context={}):                
 
61
        res = []
 
62
        if isinstance(ids, (str, int, long)):
 
63
            select = [ids]
 
64
        else:
 
65
            select = ids
 
66
        for document in self.browse(cr, uid, select):
 
67
            user_email = (document.user_id and document.user_id.address_id and document.user_id.address_id.email) or False
 
68
            res += [(user_email, False, False, False)]
 
69
        if isinstance(ids, (str, int, long)):
 
70
            return len(res) and res[0] or False
 
71
        return res
 
72
 
 
73
    def msg_send(self, cr, uid, id, *args, **argv):
 
74
        return True 
 
75
 
 
76
document_file()
 
77
 
 
78
 
 
79
class document_email_notes(osv.osv):
 
80
    _name = "document.email.notes"
 
81
    _description = "EMail Conversation Detail"
 
82
 
 
83
    def _note_get(self, cursor, user, ids, name, arg, context=None):
 
84
        res = {}
 
85
        for hist in self.browse(cursor, user, ids, context or {}):
 
86
            res[hist.id] = (hist.email or '/') + ' (' + str(hist.create_date) + ')\n'
 
87
            res[hist.id] += (hist.description or '')
 
88
        return res
 
89
 
 
90
    _columns = {
 
91
        'name': fields.char("Name", size=64, required=True, select=True),
 
92
        'description': fields.text('Description'),
 
93
        'note': fields.function(_note_get, method=True, string="Description", type="text"),
 
94
        'email': fields.char('Email', size=84),  
 
95
        'create_date': fields.datetime('Created Date'),  
 
96
        'action': fields.char('Action', size=64),
 
97
        'document_id': fields.many2one('ir.attachment','Document', required=True),    
 
98
    }
 
99
document_email_notes()