From 6883726ee4e3ace00e0120cf28c1ec2c79e316c5 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Wed, 2 Jun 2010 12:09:55 +0530 Subject: [PATCH] [IMP]: mail_gateway: Improvement in mailgateway for message-id bzr revid: rpa@tinyerp.com-20100602063955-8q61fvzqggvo7eq8 --- addons/crm/wizard/crm_send_email.py | 9 ++++++--- addons/mail_gateway/mail_gateway.py | 10 ++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index f6b5f88c4e1..8d394ddcf9e 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -20,11 +20,12 @@ # ############################################################################## +from crm import crm from osv import osv, fields from tools.translate import _ import base64 +import time import tools -from crm import crm class crm_send_new_email(osv.osv_memory): """ Sends new email for the case""" @@ -93,10 +94,12 @@ class crm_send_new_email(osv.osv_memory): if context.get('mail', 'new') == 'new': if len(case.message_ids): message_id = case.message_ids[0].message_id + else: + message_id = "<%s-openerp-@%s-%s-%d>" % (time.time(), cr.dbname, model, res_id) else: hist = hist_obj.browse(cr, uid, res_id) message_id = hist.message_id - model = hist.model_id.model + model = hist.model model_pool = self.pool.get(model) res_ids = model_pool.search(cr, uid, [('thread_id','=', hist.thread_id.id)]) res_id = res_ids and res_ids[0] or False @@ -196,7 +199,7 @@ class crm_send_new_email(osv.osv_memory): include_original = context and context.get('include_original', False) or False res = {} for hist in hist_obj.browse(cr, uid, res_ids, context=context): - model = hist.model_id.model + model = hist.model # In the case where the crm.case does not exist in the database if not model: diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py index 221dce21cbd..5a4ab95c935 100644 --- a/addons/mail_gateway/mail_gateway.py +++ b/addons/mail_gateway/mail_gateway.py @@ -80,11 +80,11 @@ class mailgate_thread(osv.osv): obj = self.pool.get('mailgate.message') for case in cases: - model_ids = model_obj.search(cr, uid, [('model', '=', case._name)]) data = { 'name': keyword, 'user_id': uid, - 'model_id' : model_ids and model_ids[0] or False, + 'model' : case._name, + 'res_id': case.id, 'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'thread_id': case.thread_id.id, 'message_id': message_id, @@ -98,7 +98,7 @@ class mailgate_thread(osv.osv): 'name': subject or 'History', 'history': True, 'user_id': uid, - 'model_id' : model_ids and model_ids[0] or False, + 'model' : case._name, 'res_id': case.id, 'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'description': details or (hasattr(case, 'description') and case.description or False), @@ -144,7 +144,9 @@ class mailgate_message(osv.osv): 'message_id': fields.char('Message Id', size=1024, readonly=True, help="Message Id on Email Server.", select=True), 'description': fields.text('Description'), 'partner_id': fields.many2one('res.partner', 'Partner', required=False), - 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments'), + 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments'), + 'model': fields.char('Model Name', size=64, required=False), + 'res_id': fields.integer('Resource ID'), } mailgate_message()