From b794d93e2a42eac8f3466c290b5ce7bdfc8a8547 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 21 Apr 2011 14:41:25 +0530 Subject: [PATCH 1/3] [FIX] thunderbird: changes in partner.py for history() bzr revid: rha@tinyerp.com-20110421091125-nevt80ac5y1vn5jy --- addons/mail/email_message.py | 2 +- addons/mail/email_thread.py | 9 ++++---- addons/thunderbird/partner/partner.py | 33 ++++++++------------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/addons/mail/email_message.py b/addons/mail/email_message.py index b9e1a7a368e..6fb1bc87035 100644 --- a/addons/mail/email_message.py +++ b/addons/mail/email_message.py @@ -295,6 +295,7 @@ class email_message(osv.osv): """Return Dictionary Object after parse EML Message String @param message: email.message.Message object or string or unicode object """ + msg_txt = message if isinstance(message, str): msg_txt = email.message_from_string(message) @@ -304,7 +305,6 @@ class email_message(osv.osv): message = message.encode('utf-8') msg_txt = email.message_from_string(message) - msg_txt = message message_id = msg_txt.get('message-id', False) msg = {} diff --git a/addons/mail/email_thread.py b/addons/mail/email_thread.py index 796fc35bb92..df26adab354 100644 --- a/addons/mail/email_thread.py +++ b/addons/mail/email_thread.py @@ -158,10 +158,7 @@ class email_thread(osv.osv): if attach is None: attach = {} - model = context.get('thread_model', False) - if not model: - model = self._name - model_pool = self.pool.get(model) + if email_date: edate = parsedate(email_date) @@ -171,6 +168,10 @@ class email_thread(osv.osv): # The script sends the ids of the threads and not the object list if all(isinstance(thread_id, (int, long)) for thread_id in threads): + model = context.get('thread_model', False) + if not model: + model = self._name + model_pool = self.pool.get(model) threads = model_pool.browse(cr, uid, threads, context=context) att_obj = self.pool.get('ir.attachment') diff --git a/addons/thunderbird/partner/partner.py b/addons/thunderbird/partner/partner.py index 3d0f2937a1f..747625532b2 100644 --- a/addons/thunderbird/partner/partner.py +++ b/addons/thunderbird/partner/partner.py @@ -23,28 +23,6 @@ from osv import osv import base64 import email import tools -import binascii -class email_thread(osv.osv): - _inherit = "email.thread" - def history_message(self, cr, uid, model, res_id, message, context=None): - #@param message: string of mail which is read from EML File - attachment_pool = self.pool.get('ir.attachment') - email_message_pool = self.pool.get('email.message') - msg = email_message_pool.parse_message(message) - attachments = msg.get('attachments', []) - att_ids = [] - for attachment in attachments: - data_attach = { - 'name': attachment, - 'datas': binascii.b2a_base64(str(attachments.get(attachment))), - 'datas_fname': attachment, - 'description': 'Mail attachment From Thunderbird msg_id: %s' %(msg.get('message_id', '')), - 'res_model': model, - 'res_id': res_id, - } - att_ids.append(attachment_pool.create(cr, uid, data_attach)) - return self.history(cr, uid, model, res_id, msg, att_ids) -email_thread() class thunderbird_partner(osv.osv_memory): _name = "thunderbird.partner" @@ -67,6 +45,7 @@ class thunderbird_partner(osv.osv_memory): msg = dictcreate.get('message') mail = msg msg = self.pool.get('email.message').parse_message(msg) + subject = msg.get('Subject', False) thread_pool = self.pool.get('email.thread') message_id = msg.get('message-id', False) msg_pool = self.pool.get('email.message') @@ -75,7 +54,6 @@ class thunderbird_partner(osv.osv_memory): res_ids = [] obj_list= ['crm.lead','project.issue','hr.applicant','res.partner'] for ref_id in ref_ids: - msg_new = dictcreate.get('message') ref = ref_id.split(',') model = ref[0] res_id = int(ref[1]) @@ -108,7 +86,14 @@ class thunderbird_partner(osv.osv_memory): res['datas'] = base64.b64encode(mail) res['res_id'] = res_id obj_attch.create(cr, uid, res) - thread_pool.history_message(cr, uid, model, res_id, msg_new) + threads = self.pool.get(model).browse(cr, uid, res_id) + thread_pool.history(cr, uid, [threads], subject, + email=msg.get('to', False), + details=msg.get('body', False), + email_from=msg.get('from', False), + message_id= msg.get('message-id', False), + attach= msg.get('attachments', {}), + email_date= msg.get('date', False)) res_ids.append(res_id) return len(res_ids) From 4b2f93cb343874fb828a62694a09a858f7cc45c0 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 21 Apr 2011 14:49:15 +0530 Subject: [PATCH 2/3] [FIX]: removed method _history() and called history() instead bzr revid: rha@tinyerp.com-20110421091915-fw1sr549av69mm4b --- addons/crm/crm.py | 21 ++++++-------------- addons/crm/crm_action_rule.py | 2 +- addons/crm/wizard/crm_merge_opportunities.py | 2 +- addons/project_issue/project_issue.py | 2 +- addons/project_mailgate/project_mailgate.py | 18 +++++------------ addons/sale_crm/wizard/crm_make_sale.py | 2 +- 6 files changed, 15 insertions(+), 32 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 0c84820b5fa..4459f7ca217 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -307,14 +307,6 @@ class crm_case(object): else: return {'value': {'phone': address.phone}} - def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None): - thread_pool = self.pool.get('email.thread') - return thread_pool.history(cr, uid, cases, keyword, history=history,\ - subject=subject, email=email, \ - details=details, email_from=email_from,\ - message_id=message_id, attach=attach, \ - context=context) - def case_open(self, cr, uid, ids, *args): """Opens Case @param self: The object pointer @@ -325,7 +317,7 @@ class crm_case(object): """ cases = self.browse(cr, uid, ids) - self._history(cr, uid, cases, _('Open')) + self.history(cr, uid, cases, _('Open')) for case in cases: data = {'state': 'open', 'active': True} if not case.user_id: @@ -346,7 +338,7 @@ class crm_case(object): """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Close')) + self.history(cr, uid, cases, _('Close')) self.write(cr, uid, ids, {'state': 'done', 'date_closed': time.strftime('%Y-%m-%d %H:%M:%S'), }) @@ -377,7 +369,7 @@ class crm_case(object): raise osv.except_osv(_('Error !'), _('You can not escalate, You are already at the top level regarding your sales-team category.')) self.write(cr, uid, [case.id], data) cases = self.browse(cr, uid, ids) - self._history(cr, uid, cases, _('Escalate')) + self.history(cr, uid, cases, _('Escalate')) self._action(cr, uid, cases, 'escalate') return True @@ -391,7 +383,7 @@ class crm_case(object): """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Cancel')) + self.history(cr, uid, cases, _('Cancel')) self.write(cr, uid, ids, {'state': 'cancel', 'active': True}) self._action(cr, uid, cases, 'cancel') @@ -410,7 +402,7 @@ class crm_case(object): """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Pending')) + self.history(cr, uid, cases, _('Pending')) self.write(cr, uid, ids, {'state': 'pending', 'active': True}) self._action(cr, uid, cases, 'pending') return True @@ -425,7 +417,7 @@ class crm_case(object): """ cases = self.browse(cr, uid, ids) cases[0].state # to fill the browse record cache - self._history(cr, uid, cases, _('Draft')) + self.history(cr, uid, cases, _('Draft')) self.write(cr, uid, ids, {'state': 'draft', 'active': True}) self._action(cr, uid, cases, 'draft') return True @@ -498,7 +490,6 @@ class crm_case(object): openobject_id=str(case.id), attach=attach_to_send ) - self._history(cr, uid, [case], _('Send'), history=True, subject=subject, email=dest, details=body, email_from=src) return True def _check(self, cr, uid, ids=False, context=None): diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index acb7801c7c9..f510ac73c4b 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -125,7 +125,7 @@ this if you want the rule to send an email to the partner."), # Put state change by rule in communication history if hasattr(obj, 'state') and action.act_state: - model_obj._history(cr, uid, [obj], _(action.act_state)) + model_obj.history(cr, uid, [obj], _(action.act_state)) model_obj.write(cr, uid, [obj.id], write, context) emails = [] diff --git a/addons/crm/wizard/crm_merge_opportunities.py b/addons/crm/wizard/crm_merge_opportunities.py index 82e3f6402fc..bdf179a48aa 100644 --- a/addons/crm/wizard/crm_merge_opportunities.py +++ b/addons/crm/wizard/crm_merge_opportunities.py @@ -148,7 +148,7 @@ class crm_merge_opportunity(osv.osv_memory): subject = subject[0] + ", ".join(subject[1:]) details = "\n\n".join(details) - opp_obj._history(cr, uid, [first_opportunity], subject, details=details) + opp_obj.history(cr, uid, [first_opportunity], subject, details=details) #data.update({'message_ids' : [(6, 0 ,self._concat_o2m('message_ids', op_ids))]}) opp_obj.write(cr, uid, [first_opportunity.id], data) unlink_ids = map(lambda x: x.id, tail_opportunities) diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index e9e5521d94b..a88ee17496e 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -361,7 +361,7 @@ class project_issue(crm.crm_case, osv.osv): else: raise osv.except_osv(_('Warning !'), _('You cannot escalate this issue.\nThe relevant Project has not configured the Escalation Project!')) self.write(cr, uid, [case.id], data) - self._history(cr, uid, cases, _('Escalate')) + self.history(cr, uid, cases, _('Escalate')) return True def message_new(self, cr, uid, msg, context=None): diff --git a/addons/project_mailgate/project_mailgate.py b/addons/project_mailgate/project_mailgate.py index dc0f04aeddf..cea05b3fa44 100644 --- a/addons/project_mailgate/project_mailgate.py +++ b/addons/project_mailgate/project_mailgate.py @@ -120,30 +120,22 @@ class project_tasks(osv.osv): return len(res) and res[0] or False return res - def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None): - thread_pool = self.pool.get('email.thread') - return thread_pool.history(cr, uid, cases, keyword, history=history,\ - subject=subject, email=email, \ - details=details, email_from=email_from,\ - message_id=message_id, attach=attach, \ - context=context) - def do_draft(self, cr, uid, ids, *args, **kwargs): res = super(project_tasks, self).do_draft(cr, uid, ids, *args, **kwargs) tasks = self.browse(cr, uid, ids) - self._history(cr, uid, tasks, _('Draft')) + self.history(cr, uid, tasks, _('Draft')) return res def do_open(self, cr, uid, ids, *args, **kwargs): res = super(project_tasks, self).do_open(cr, uid, ids, *args, **kwargs) tasks = self.browse(cr, uid, ids) - self._history(cr, uid, tasks, _('Open')) + self.history(cr, uid, tasks, _('Open')) return res def do_pending(self, cr, uid, ids, *args, **kwargs): res = super(project_tasks, self).do_pending(cr, uid, ids, *args, **kwargs) tasks = self.browse(cr, uid, ids) - self._history(cr, uid, tasks, _('Pending')) + self.history(cr, uid, tasks, _('Pending')) return res def do_close(self, cr, uid, ids, *args, **kwargs): @@ -151,13 +143,13 @@ class project_tasks(osv.osv): tasks = self.browse(cr, uid, ids) for task in tasks: if task.state == 'done': - self._history(cr, uid, tasks, _('Done')) + self.history(cr, uid, tasks, _('Done')) return res def do_cancel(self, cr, uid, ids, *args, **kwargs): res = super(project_tasks, self).do_cancel(cr, uid, ids, *args, **kwargs) tasks = self.browse(cr, uid, ids) - self._history(cr, uid, tasks, _('Cancel')) + self.history(cr, uid, tasks, _('Cancel')) return res project_tasks() diff --git a/addons/sale_crm/wizard/crm_make_sale.py b/addons/sale_crm/wizard/crm_make_sale.py index f48df128e31..2c7f6cb0d69 100644 --- a/addons/sale_crm/wizard/crm_make_sale.py +++ b/addons/sale_crm/wizard/crm_make_sale.py @@ -107,7 +107,7 @@ class crm_make_sale(osv.osv_memory): new_ids.append(new_id) message = _("Opportunity '%s' is converted to Quotation.") % (case.name) self.log(cr, uid, case.id, message) - case_obj._history(cr, uid, [case], _("Converted to Sales Quotation(id: %s).") % (new_id)) + case_obj.history(cr, uid, [case], _("Converted to Sales Quotation(id: %s).") % (new_id)) if make.close: case_obj.case_close(cr, uid, data) From 2c9825a07be5c6c76f488c82bda23f31c0b1d2fc Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 21 Apr 2011 15:23:16 +0530 Subject: [PATCH 3/3] [FIX] thunderbird: changes in history() of partner.py bzr revid: rha@tinyerp.com-20110421095316-zccag93g4spnzeja --- addons/thunderbird/partner/partner.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/thunderbird/partner/partner.py b/addons/thunderbird/partner/partner.py index 747625532b2..d67238db5fc 100644 --- a/addons/thunderbird/partner/partner.py +++ b/addons/thunderbird/partner/partner.py @@ -87,13 +87,16 @@ class thunderbird_partner(osv.osv_memory): res['res_id'] = res_id obj_attch.create(cr, uid, res) threads = self.pool.get(model).browse(cr, uid, res_id) - thread_pool.history(cr, uid, [threads], subject, - email=msg.get('to', False), - details=msg.get('body', False), - email_from=msg.get('from', False), - message_id= msg.get('message-id', False), - attach= msg.get('attachments', {}), - email_date= msg.get('date', False)) + thread_pool.history(cr, uid, [threads], _('receive'), history=True, + subject = msg.get('subject'), + email = msg.get('to'), + details = msg.get('body'), + email_from = msg.get('from'), + email_cc = msg.get('cc'), + message_id = msg.get('message-id'), + references = msg.get('references', False) or msg.get('in-reply-to', False), + attach = msg.get('attachments', {}), + email_date = msg.get('date')) res_ids.append(res_id) return len(res_ids)