[REF] Remove the context={} in the code and use context=None,

[REF] use the concept of mailgate.message

bzr revid: stephane@openerp.com-20100611132624-plg9ng6nbn3j2zoi
This commit is contained in:
Stephane Wirtel 2010-06-11 15:26:24 +02:00
parent 58e9a51264
commit 2089f1cd2e
2 changed files with 47 additions and 34 deletions

View File

@ -32,11 +32,12 @@ from tools.translate import _
import tools
from osv import fields,osv,orm
from osv.orm import except_orm
import collections
from tools import command_re
class crm_cases(osv.osv):
""" crm cases """
class mailgate_thread(osv.osv):
""" mailgate_thread """
_name = "mailgate.thread"
_inherit = "mailgate.thread"
@ -127,7 +128,7 @@ class crm_cases(osv.osv):
#getattr(self, act)(cr, uid, select)
return res
def emails_get(self, cr, uid, ids, context={}):
def emails_get(self, cr, uid, ids, context=None):
"""
Get Emails
@ -137,16 +138,24 @@ class crm_cases(osv.osv):
@param ids: List of emails IDs
@param context: A standard dictionary for contextual values
"""
res = []
res = {}
if isinstance(ids, (str, int, long)):
select = [ids]
select = [long(ids)]
else:
select = ids
for case in self.browse(cr, uid, select):
user_email = (case.user_id and case.user_id.address_id and case.user_id.address_id.email) or False
res += [(user_email, case.email_from, case.email_cc or False, getattr(case,'priority') and case.priority or False)]
if isinstance(ids, (str, int, long)):
return len(res) and res[0] or False
for thread in self.browse(cr, uid, select, context=context):
values = collections.defaultdict(set)
for message in thread.message_ids:
user_email = (message.user_id and message.user_id.address_id and message.user_id.address_id.email) or False
values['user_email'].add(user_email)
values['email_from'].add(message.email_from)
values['email_cc'].add(message.email_cc or False)
res[str(thread.id)] = dict((key,list(values[key])) for key, value in values.iteritems())
return res
def msg_send(self, cr, uid, id, *args, **argv):
@ -161,4 +170,4 @@ class crm_cases(osv.osv):
"""
return True
crm_cases()
mailgate_thread()

View File

@ -53,9 +53,9 @@ class mailgate_thread(osv.osv):
'thread': fields.char('Thread', size=32, required=False),
'message_ids': one2many_domain('mailgate.message', 'thread_id', 'Messages', domain=[('history', '=', True)], required=False),
'log_ids': one2many_domain('mailgate.message', 'thread_id', 'Logs', domain=[('history', '=', False)], required=False),
}
}
def __history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context={}):
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):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@ -69,9 +69,13 @@ class mailgate_thread(osv.osv):
@param context: A standard dictionary for contextual values"""
if context is None:
context = {}
if attach is None:
attach = []
# The mailgate sends the ids of the cases and not the object list
if all(isinstance(case_id, (int, long)) for case_id in cases) and context.get('model'):
cases = self.pool.get(context['model']).browse(cr, uid, cases, context=context)
if all(isinstance(case_id, (int, long)) for case_id in cases):
cases = self.browse(cr, uid, cases, context=context)
model_obj = self.pool.get('ir.model')
att_obj = self.pool.get('ir.attachment')
@ -84,7 +88,7 @@ class mailgate_thread(osv.osv):
'user_id': uid,
'model_id' : model_ids and model_ids[0] or False,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'thread_id': case.thread_id.id,
'thread_id': case.thread_id.id,
'message_id': message_id,
}
attachments = []
@ -93,24 +97,24 @@ class mailgate_thread(osv.osv):
attachments.append(att_obj.create(cr, uid, {'name': att[0], 'datas': base64.encodestring(att[1])}))
data = {
'name': subject or 'History',
'history': True,
'user_id': uid,
'model_id' : model_ids and model_ids[0] or False,
'res_id': case.id,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'description': details or (hasattr(case, 'description') and case.description or False),
'email_to': email or \
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
case.user_id.address_id.email) or tools.config.get('email_from', False),
'email_from': email_from or \
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
case.user_id.address_id.email) or tools.config.get('email_from', False),
'partner_id': hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False,
'thread_id': case.thread_id.id,
'message_id': message_id,
'attachment_ids': [(6, 0, attachments)]
}
'name': subject or 'History',
'history': True,
'user_id': uid,
'model_id' : model_ids and model_ids[0] or False,
'res_id': case.id,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'description': details or (hasattr(case, 'description') and case.description or False),
'email_to': email or \
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
case.user_id.address_id.email) or tools.config.get('email_from', False),
'email_from': email_from or \
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
case.user_id.address_id.email) or tools.config.get('email_from', False),
'partner_id': hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False,
'thread_id': case.thread_id.id,
'message_id': message_id,
'attachment_ids': [(6, 0, attachments)]
}
res = obj.create(cr, uid, data, context)
return True