From 1187aae83a8a73d6006dea2a6f2d298934986696 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Fri, 11 Jun 2010 15:08:53 +0200 Subject: [PATCH 1/6] [IMP] better views and security rules bzr revid: fp@tinyerp.com-20100611130853-scoz86mdvte7ynwm --- addons/crm/security/ir.model.access.csv | 2 +- addons/hr_attendance/security/ir.model.access.csv | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/crm/security/ir.model.access.csv b/addons/crm/security/ir.model.access.csv index a6935144e7e..8befbd8c084 100644 --- a/addons/crm/security/ir.model.access.csv +++ b/addons/crm/security/ir.model.access.csv @@ -34,5 +34,5 @@ "access_res_partner","res.partner.crm.user","base.model_res_partner","crm.group_crm_user",1,0,0,0 "access_res_partner_address","res.partner.address.crm.user","base.model_res_partner_address","crm.group_crm_user",1,0,0,0 "access_res_partner_category","res.partner.category.crm.user","base.model_res_partner_category","crm.group_crm_user",1,0,0,0 -"mail_gateway_mailgate_message","mail_gateway.mailgate.message","model_mailgate_message","crm.group_crm_user",1,1,1,1 +"mail_gateway_mailgate_message","mail_gateway.mailgate.message","mail_gateway.model_mailgate_message","crm.group_crm_user",1,1,1,1 "mail_gateway_mailgate_thread","mail_gateway.mailgate.thread","model_mailgate_thread","crm.group_crm_user",1,1,1,1 diff --git a/addons/hr_attendance/security/ir.model.access.csv b/addons/hr_attendance/security/ir.model.access.csv index 69032ff5ccf..6150427e520 100644 --- a/addons/hr_attendance/security/ir.model.access.csv +++ b/addons/hr_attendance/security/ir.model.access.csv @@ -1,5 +1,5 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_hr_action_reason_employee","hr action reason employee","model_hr_action_reason","hr.group_hr_attendance",1,0,0,0 +"access_hr_action_reason_employee","hr action reason employee","model_hr_action_reason","hr_attendance.group_hr_attendance",1,0,0,0 "access_hr_action_reason_employee","hr action reason employee","model_hr_action_reason","hr.group_hr_manager",1,1,1,1 -"access_hr_attendance_employee","hr attendance employee","model_hr_attendance","hr.group_hr_attendance",1,1,1,1 -"access_hr_sign_in_out","hr attendance sign in out","model_hr_sign_in_out","hr.group_hr_attendance",1,1,1,1 +"access_hr_attendance_employee","hr attendance employee","model_hr_attendance","hr_attendance.group_hr_attendance",1,1,1,1 +"access_hr_sign_in_out","hr attendance sign in out","model_hr_sign_in_out","hr_attendance.group_hr_attendance",1,1,1,1 From 9ace325340dd37fb8c520875740099cd02670391 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Fri, 11 Jun 2010 15:11:17 +0200 Subject: [PATCH 2/6] fix bzr revid: fp@tinyerp.com-20100611131117-olu362rdfp3b5bwz --- addons/hr_recruitment/hr_recruitment.py | 3 +-- addons/hr_recruitment/hr_recruitment_data.xml | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 42d643f165d..b11fc27b88b 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -77,7 +77,7 @@ class hr_applicant(osv.osv, crm.crm_case): domain="[('partner_id','=',partner_id)]"), 'create_date': fields.datetime('Creation Date' , readonly=True), 'write_date': fields.datetime('Update Date' , readonly=True), - 'stage_id': fields.many2one ('crm.case.stage', 'Stage', \ + 'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage', \ domain="[('section_id','=',section_id),\ ('object_id.model', '=', 'crm.opportunity')]"), 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True, @@ -98,7 +98,6 @@ class hr_applicant(osv.osv, crm.crm_case): 'partner_name': fields.char("Applicant's Name", size=64), 'partner_phone': fields.char('Phone', size=32), 'partner_mobile': fields.char('Mobile', size=32), - 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]"), 'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]"), 'department_id':fields.many2one('hr.department', 'Department'), 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True), diff --git a/addons/hr_recruitment/hr_recruitment_data.xml b/addons/hr_recruitment/hr_recruitment_data.xml index 77f15c4afd5..7661b60a1fa 100644 --- a/addons/hr_recruitment/hr_recruitment_data.xml +++ b/addons/hr_recruitment/hr_recruitment_data.xml @@ -30,8 +30,6 @@ - - Initial Jobs Demand From af11764749a12bf3782f0e58ebd5f855d907584c Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Fri, 11 Jun 2010 15:12:09 +0200 Subject: [PATCH 3/6] fix bzr revid: fp@tinyerp.com-20100611131209-wr034qpphp4im9xa --- addons/hr_recruitment/hr_recruitment_view.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index 5183587e992..99647cd2406 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -25,11 +25,10 @@ # ------------------------------------------------------ Applicant Stages - crm.case.stage + hr.recruitment.stage form - - [('object_id.model', '=', 'hr.applicant')] - {'object_id':'hr.applicant'} + [] + {} From 220eac16121282893b6c17d4bbd594b2245396c2 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Fri, 11 Jun 2010 15:22:11 +0200 Subject: [PATCH 4/6] fix bzr revid: fp@tinyerp.com-20100611132211-zd8zff7aq2ifgsde --- addons/hr_timesheet/security/ir.model.access.csv | 4 ++-- addons/hr_timesheet_invoice/security/ir.model.access.csv | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/hr_timesheet/security/ir.model.access.csv b/addons/hr_timesheet/security/ir.model.access.csv index 1b1c38e5cf0..ce51366f383 100644 --- a/addons/hr_timesheet/security/ir.model.access.csv +++ b/addons/hr_timesheet/security/ir.model.access.csv @@ -2,6 +2,6 @@ "access_hr_analytic_timesheet","hr.analytic.timesheet","model_hr_analytic_timesheet","hr.group_hr_user",1,1,1,1 "access_hr_account_analytic_line","account.account.analytic.line","account.model_account_analytic_line","hr.group_hr_user",1,1,1,0 "access_account_analytic_journal","account.account.analytic.journal","account.model_account_analytic_journal","hr.group_hr_user",1,0,0,0 -"access_hr_sign_in_project","hr.sign.in.project attendance","model_hr_sign_in_project","hr_attendance.group_hr_tendance",1,0,0,0 +"access_hr_sign_in_project","hr.sign.in.project attendance","model_hr_sign_in_project","hr_attendance.group_hr_attendance",1,0,0,0 "access_hr_analytal_timesheet_employee","hr.analytical.timesheet.employee","model_hr_analytical_timesheet_employee","hr.group_hr_manager",1,1,1,1 -"access_hr_analytal_timesheet_user","hr.analytical.timesheet.user","model_hr_analytical_timesheet_user","hr.group_hr_user",1,1,1,1 +"access_hr_analytal_timesheet_user","hr.analytical.timesheet.user","model_hr_analytical_timesheet_users","hr.group_hr_user",1,1,1,1 diff --git a/addons/hr_timesheet_invoice/security/ir.model.access.csv b/addons/hr_timesheet_invoice/security/ir.model.access.csv index b9cd593c824..f6d344cfb31 100644 --- a/addons/hr_timesheet_invoice/security/ir.model.access.csv +++ b/addons/hr_timesheet_invoice/security/ir.model.access.csv @@ -9,4 +9,4 @@ "access_report_timesheet_invoice","report_timesheet.invoice","model_report_timesheet_invoice","hr.group_hr_manager",1,0,0,0 "access_report_random_timesheet","report_random_timesheet","model_report_random_timesheet","hr.group_hr_manager",1,0,0,0 "access_report_random_timesheet_lines","random_timesheet_lines","model_random_timesheet_lines","hr.group_hr_manager",1,0,0,0 -"access_hr_timesheet_analytic_profit","hr_timesheet_analytic_profit","model_hr_timesheet_analytic_profit","hr.group_account_invoice",1,1,1,1 +"access_hr_timesheet_analytic_profit","hr_timesheet_analytic_profit","model_hr_timesheet_analytic_profit","account.group_account_invoice",1,1,1,1 From 58e9a51264038e97e4ac99a3a64ac10d68e4c26a Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Fri, 11 Jun 2010 15:07:16 +0200 Subject: [PATCH 5/6] [FIX] Add the copyright of OpenERP S.A. [REF] Remove unless code [IMP] Use the new mailgate.thread, mailgate.message concept for the communication history of a crm.* object (can be used with an other object with the thread_id#mailgate.thread) field [IMP] Add a logging support bzr revid: stephane@openerp.com-20100611130716-wpclu61sqza7lg5h --- .../openerp_mailgate/openerp_mailgate.py | 189 ++++++++++-------- 1 file changed, 107 insertions(+), 82 deletions(-) diff --git a/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py index a865443c1b9..95543fcb7f6 100755 --- a/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py @@ -3,7 +3,8 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). +# Copyright (C) 2004-2009 Tiny SPRL (). +# Copyright (C) 2010-TODAY OpenERP S.A. (http://www.openerp.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -22,14 +23,18 @@ import re import smtplib -import email, mimetypes +import email +import mimetypes from email.Header import decode_header from email.MIMEText import MIMEText import xmlrpclib import os import binascii -import time, socket - +import time +import socket +import logging +import sys +import optparse email_re = re.compile(r"([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6})") case_re = re.compile(r"\[([0-9]+)\]", re.UNICODE) @@ -89,7 +94,6 @@ def html2plaintext(html, body_id=None, encoding='utf-8'): html = html.replace('

', '**').replace('

', '**') html = html.replace('

', '**').replace('

', '**') html = html.replace('', '/').replace('', '/') - # the only line breaks we respect is those of ending tags and # breaks @@ -101,14 +105,7 @@ def html2plaintext(html, body_id=None, encoding='utf-8'): html = re.sub('', '\n', html) html = html.replace(' ' * 2, ' ') - - # for all other tags we failed to clean up, just remove then and - # complain about them on the stderr - def desperate_fixer(g): - #print >>sys.stderr, "failed to clean up %s" % str(g.group()) - return ' ' - - html = re.sub('<.*?>', desperate_fixer, html) + html = re.sub('<.*?>', ' ', html) # lstrip all lines html = '\n'.join([x.lstrip() for x in html.splitlines()]) @@ -166,10 +163,11 @@ class email_parser(object): pass return s.decode('latin1') - def _decode_header(self, s): + def _decode_header(self, text): from email.Header import decode_header - s = decode_header(s.replace('\r', '')) - return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), s or [])) + if text: + text = decode_header(text.replace('\r', '')) + return ''.join(map(lambda x:self._to_decode(x[0], [x[1]]), text or [])) def msg_new(self, msg): message = self.msg_body_get(msg) @@ -188,14 +186,25 @@ class email_parser(object): } data.update(self.partner_get(msg_from)) - try: - id = self.rpc(self.model, 'create', data) - self.rpc(self.model, 'history', [id], 'Receive', True, msg_to, message['body'], msg_from, False, {'model' : self.model}) - #self.rpc(self.model, 'case_open', [id]) - except Exception, e: - if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode: - e = '\n\nThe Specified user does not have an access to the CRM case.' - print e + values = { + 'message_ids' : [ + (0, 0, { + 'model_id' : self.rpc('ir.model', 'search', [('name', '=', self.model)])[0], + 'date' : time.strftime('%Y-%m-%d %H:%M:%S'), + 'description' : message['body'], + 'email_from' : msg_from, + 'email_to' : msg_to, + 'name' : 'Receive', + 'history' : True, + 'user_id' : self.rpc.user_id, + } + ) + ] + } + thread_id = self.rpc('mailgate.thread', 'create', values) + data['thread_id'] = thread_id + oid = self.rpc(self.model, 'create', data) + attachments = message['attachment'] for attach in attachments or []: data_attach = { @@ -204,30 +213,19 @@ class email_parser(object): 'datas_fname': str(attach), 'description': 'Mail attachment', 'res_model': self.model, - 'res_id': id + 'res_id': oid } self.rpc('ir.attachment', 'create', data_attach) - return id - -# #change the return type format to dictionary -# { -# 'body':'body part', -# 'attachment':{ -# 'file_name':'file data', -# 'file_name':'file data', -# 'file_name':'file data', -# } -# } + return (oid, thread_id,) def msg_body_get(self, msg): - message = {}; - message['body'] = ''; - message['attachment'] = {}; + message = { + 'body' : '', + 'attachment' : {}, + } attachment = message['attachment']; counter = 1; - def replace(match): - return '' for part in msg.walk(): if part.get_content_maintype() == 'multipart': @@ -237,27 +235,23 @@ class email_parser(object): buf = part.get_payload(decode=True) if buf: txt = self._to_decode(buf, part.get_charsets()) - txt = re.sub("<(\w)>", replace, txt) - txt = re.sub("<\/(\w)>", replace, txt) + txt = re.sub("<\/?(\w)>", '', txt) if txt and part.get_content_subtype() == 'plain': message['body'] += txt - elif txt and part.get_content_subtype() == 'html': + elif txt and part.get_content_subtype() == 'html': message['body'] += html2plaintext(txt) - + filename = part.get_filename(); if filename : attachment[filename] = part.get_payload(decode=True); - - elif part.get_content_maintype()=='application' or part.get_content_maintype()=='image' or part.get_content_maintype()=='text': + + elif part.get_content_maintype() in ('application', 'image', 'text'): filename = part.get_filename(); - if filename : - attachment[filename] = part.get_payload(decode=True); - else: + if not filename : filename = 'attach_file'+str(counter); counter += 1; - attachment[filename] = part.get_payload(decode=True); - #end if - #end if + + attachment[filename] = part.get_payload(decode=True); message['attachment'] = attachment #end for return message @@ -316,22 +310,42 @@ class email_parser(object): } self.rpc('ir.attachment', 'create', data_attach) - self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['To']), body['body'], self._decode_header(msg['From']), False, {'model' : self.model}) + self.create_message(id, msg['From'], msg['To'], 'Send', message['body']) + return id + def create_message(self, oid, email_from, email_to, name, body): + """ + This functions creates a message in the thread + + > create_message(id, msg['From'], msg['To'], 'Send', message['body']) + """ + values = { + 'thread_id' : self.rpc(self.model, 'read', [oid], ['thread_id'])[0]['thread_id'][0], + 'model_id' : self.rpc('ir.model', 'search', [('name', '=', self.model)])[0], + 'res_id' : oid, + 'date' : time.strftime('%Y-%m-%d %H:%M:%S'), + 'description' : body, + 'email_from' : self._decode_header(email_from), + 'email_to' : self._decode_header(email_to), + 'name' : name, + 'history' : True, + 'user_id' : self.rpc.user_id, + } + return self.rpc('mailgate.message', 'create', values) + def msg_send(self, msg, emails, priority=None): - if not len(emails): + if not emails: return False - del msg['To'] + msg['To'] = emails[0] - if len(emails)>1: - if 'Cc' in msg: - del msg['Cc'] + if len(emails) > 1: msg['Cc'] = ','.join(emails[1:]) - del msg['Reply-To'] msg['Reply-To'] = self.email + if priority: msg['X-Priority'] = priorities.get(priority, '3 (Normal)') + s = smtplib.SMTP() s.connect() s.sendmail(self.email, emails, msg.as_string()) @@ -343,11 +357,6 @@ class email_parser(object): body = message['body'] act = 'case_open' self.rpc(self.model, act, [id]) - #body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n'))) - #data = { - # 'description':body, - #} - #self.rpc(self.model, 'write', [id], data) attachments = message['attachment'] for attach in attachments or []: data_attach = { @@ -360,14 +369,16 @@ class email_parser(object): } self.rpc('ir.attachment', 'create', data_attach) - self.rpc(self.model, 'history', [id], 'Send', True, self._decode_header(msg['To']), message['body'], self._decode_header(msg['From']), False, {'model' : self.model}) + self.create_message(id, msg['From'], msg['To'], 'Send', message['body']) return id def msg_test(self, msg, case_str): if not case_str: return (False, False) - emails = self.rpc(self.model, 'emails_get', int(case_str)) - return (int(case_str), emails) + + case_id = int(case_str) + emails = self.rpc(self.model, 'emails_get', [case_id]) + return (case_id, emails) def parse(self, msg): case_str = reference_re.search(msg.get('References', '')) @@ -377,23 +388,37 @@ class email_parser(object): case_str = case_re.search(msg.get('Subject', '')) if case_str: case_str = case_str.group(1) + + logging.info("email: %s -> %s -- %s", msg['From'], self.email, msg['Subject']) (case_id, emails) = self.msg_test(msg, case_str) + thread_id = None if case_id: - if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): + values = self.rpc(self.model, 'read', [case_id], ['thread_id']) + if values: + thread_id = values[0]['thread_id'][0] + emails = emails[str(thread_id)] + + user_email = filter(None, emails['user_email'])[0] + + if user_email and self.email_get(user_email) == self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) else: self.msg_partner(msg, case_id) else: - case_id = self.msg_new(msg) - subject = self._decode_header(msg['subject']) - if msg.get('Subject', ''): - del msg['Subject'] - msg['Subject'] = '['+str(case_id)+'] '+subject - msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>' + case_id, thread_id = self.msg_new(msg) + subject = self._decode_header(msg['Subject']) + msg['Subject'] = "[%s] %s" % (case_id, subject,) + msg['Message-Id'] = "<%s-openerpcrm-%s@%s>" % (time.time(), case_id, socket.gethostname(),) - emails = self.rpc(self.model, 'emails_get', case_id) - priority = emails[3] - em = [emails[0], emails[1]] + (emails[2] or '').split(',') + logging.info(" case: %r", case_id) + logging.info(" thread: %r", thread_id) + + values = self.rpc(self.model, 'emails_get', [case_id]) + + emails = values[str(thread_id)] + + priority = emails.get('piority', [3])[0] + em = emails['user_email'] + emails['email_from'] + emails['email_cc'] emails = map(self.email_get, filter(None, em)) mm = [self._decode_header(msg['From']), self._decode_header(msg['To'])]+self._decode_header(msg.get('Cc', '')).split(',') @@ -405,13 +430,11 @@ class email_parser(object): except: if self.email_default: a = self._decode_header(msg['Subject']) - del msg['Subject'] msg['Subject'] = '[OpenERP-CaseError] ' + a self.msg_send(msg, self.email_default.split(',')) - return case_id, emails + return case_id, thread_id, emails if __name__ == '__main__': - import sys, optparse parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.0') group = optparse.OptionGroup(parser, "Note", "This program parse a mail from standard input and communicate " @@ -426,8 +449,10 @@ if __name__ == '__main__': parser.add_option("--host", dest="host", help="Hostname of the Open ERP Server", default="localhost") parser.add_option("--port", dest="port", help="Port of the Open ERP Server", default="8069") - (options, args) = parser.parse_args() + + logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s") + parser = email_parser(options.userid, options.password, options.model, options.email, options.default, dbname=options.dbname, host=options.host, port=options.port) msg_txt = email.message_from_file(sys.stdin) From 2089f1cd2ed6938d331c939b46c7f1bcff468dcb Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Fri, 11 Jun 2010 15:26:24 +0200 Subject: [PATCH 6/6] [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 --- addons/crm/crm_mailgate.py | 31 +++++++++++------- addons/mail_gateway/mail_gateway.py | 50 ++++++++++++++++------------- 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