summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorStephane Wirtel <stephane@openerp.com>2010-06-11 15:26:24 +0200
committerStephane Wirtel <stephane@openerp.com>2010-06-11 15:26:24 +0200
commit2089f1cd2ed6938d331c939b46c7f1bcff468dcb (patch)
tree2550ebabb853647a9ce7cde8b30f2f1a5dd3ff9e /addons
parent58e9a51264038e97e4ac99a3a64ac10d68e4c26a (diff)
[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
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/crm_mailgate.py31
-rw-r--r--addons/mail_gateway/mail_gateway.py50
2 files changed, 47 insertions, 34 deletions
diff --git a/addons/crm/crm_mailgate.py b/addons/crm/crm_mailgate.py
index 00fa761f51d..f2380182aad 100644
--- a/addons/crm/crm_mailgate.py
+++ b/addons/crm/crm_mailgate.py
@@ -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 email’s 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()
diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py
index fb4920e9632..c19f1767fa6 100644
--- a/addons/mail_gateway/mail_gateway.py
+++ b/addons/mail_gateway/mail_gateway.py
@@ -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