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 osv, fields
26 class mailgate_thread(osv.osv):
30 _name = 'mailgate.thread'
31 _description = 'Mailgateway Thread'
35 'thread': fields.char('Thread', size=32, required=False),
36 'message_ids': fields.one2many('mailgate.message', 'thread_id', 'Messages', domain=[('history', '=', True)], required=False),
37 'log_ids': fields.one2many('mailgate.message', 'thread_id', 'Logs', domain=[('history', '=', False)], required=False),
40 def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=None, context=None):
42 @param self: The object pointer
43 @param cr: the current row, from the database cursor,
44 @param uid: the current user’s ID for security checks,
45 @param cases: a browse record list
46 @param keyword: Case action keyword e.g.: If case is closed "Close" keyword is used
47 @param history: Value True/False, If True it makes entry in case History otherwise in Case Log
48 @param email: Email address if any
49 @param details: Details of case history if any
50 @param atach: Attachment sent in email
51 @param context: A standard dictionary for contextual values"""
57 # The mailgate sends the ids of the cases and not the object list
59 if all(isinstance(case_id, (int, long)) for case_id in cases):
60 cases = self.browse(cr, uid, cases, context=context)
62 model_obj = self.pool.get('ir.model')
63 att_obj = self.pool.get('ir.attachment')
64 obj = self.pool.get('mailgate.message')
67 model_ids = model_obj.search(cr, uid, [('model', '=', case._name)])
71 'model_id' : model_ids and model_ids[0] or False,
72 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
73 'thread_id': case.thread_id.id,
74 'message_id': message_id,
79 attachments.append(att_obj.create(cr, uid, {'name': att[0], 'datas': base64.encodestring(att[1])}))
82 'name': subject or 'History',
85 'model_id' : model_ids and model_ids[0] or False,
87 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
88 'description': details or (hasattr(case, 'description') and case.description or False),
89 'email_to': email or \
90 (hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
91 case.user_id.address_id.email) or tools.config.get('email_from', False),
92 'email_from': email_from or \
93 (hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
94 case.user_id.address_id.email) or tools.config.get('email_from', False),
95 'partner_id': hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False,
96 'thread_id': case.thread_id.id,
97 'message_id': message_id,
98 'attachment_ids': [(6, 0, attachments)]
100 res = obj.create(cr, uid, data, context)
103 __history = history = _history
108 class mailgate_message(osv.osv):
112 _name = 'mailgate.message'
113 _description = 'Mailgateway Message'
117 'name':fields.char('Message', size=64),
118 'model_id': fields.many2one('ir.model', 'Model'),
119 'res_id': fields.integer('Resource ID'),
120 'thread_id':fields.many2one('mailgate.thread', 'Thread'),
121 'date': fields.datetime('Date'),
122 'history': fields.boolean('Is History?', required=False),
123 'user_id': fields.many2one('res.users', 'User Responsible', readonly=True),
124 'message': fields.text('Description'),
125 'email_from': fields.char('Email From', size=84),
126 'email_to': fields.char('Email To', size=84),
127 'email_cc': fields.char('Email CC', size=84),
128 'email_bcc': fields.char('Email BCC', size=84),
129 'message_id': fields.char('Message Id', size=1024, readonly=True, help="Message Id on Email Server.", select=True),
130 'description': fields.text('Description'),
131 'partner_id': fields.many2one('res.partner', 'Partner', required=False),
132 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments'),
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: