diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index e796cf7e654..c9104421866 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -348,7 +348,22 @@ class crm_lead(crm_case, osv.osv): if res: vals.update(res) - return self.create(cr, uid, vals, context) + res_id = self.create(cr, uid, vals, context) + + attachments = msg.get('attachments', []) + self.history(cr, uid, [res_id], _('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 = attachments, + email_date = msg.get('date'), + context = context) + + return res_id def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None): """ diff --git a/addons/crm_claim/crm_claim.py b/addons/crm_claim/crm_claim.py index f5cceb59498..9a2ff90acc0 100644 --- a/addons/crm_claim/crm_claim.py +++ b/addons/crm_claim/crm_claim.py @@ -202,7 +202,22 @@ class crm_claim(crm.crm_case, osv.osv): if res: vals.update(res) - return self.create(cr, uid, vals, context) + res_id = self.create(cr, uid, vals, context) + + attachments = msg.get('attachments', []) + self.history(cr, uid, [res_id], _('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 = attachments, + email_date = msg.get('date'), + context = context) + + return res_id def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None): """ diff --git a/addons/crm_helpdesk/crm_helpdesk.py b/addons/crm_helpdesk/crm_helpdesk.py index ff503a8fb3e..03d16306df7 100644 --- a/addons/crm_helpdesk/crm_helpdesk.py +++ b/addons/crm_helpdesk/crm_helpdesk.py @@ -126,7 +126,22 @@ class crm_helpdesk(crm.crm_case, osv.osv): if res: vals.update(res) - return self.create(cr, uid, vals, context) + res_id = self.create(cr, uid, vals, context) + + attachments = msg.get('attachments', []) + self.history(cr, uid, [res_id], _('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 = attachments, + email_date = msg.get('date'), + context = context) + + return res_id def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None): """ diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 24b226f922e..f129934e8c0 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -327,7 +327,22 @@ class hr_applicant(crm.crm_case, osv.osv): res = thread_pool.get_partner(cr, uid, msg.get('from')) if res: vals.update(res) - return self.create(cr, uid, vals, context=context) + res_id = self.create(cr, uid, vals, context) + + attachments = msg.get('attachments', []) + self.history(cr, uid, [res_id], _('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 = attachments, + email_date = msg.get('date'), + context = context) + + return res_id def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None): """ diff --git a/addons/mail/email_thread.py b/addons/mail/email_thread.py index 78d5b18886f..f1ef3858fed 100644 --- a/addons/mail/email_thread.py +++ b/addons/mail/email_thread.py @@ -75,14 +75,11 @@ class email_thread(osv.osv): if not model: model = self._name model_pool = self.pool.get(model) - if hasattr(model_pool, 'message_new'): - res_id = model_pool.message_new(cr, uid, msg, context) - else: - fields = model_pool.fields_get(cr, uid, context=context) - data = model_pool.default_get(cr, uid, fields, context=context) - if 'name' in fields and not data.get('name',False): - data['name'] = msg.get('from','') - res_id = model_pool.create(cr, uid, data, context=context) + fields = model_pool.fields_get(cr, uid, context=context) + data = model_pool.default_get(cr, uid, fields, context=context) + if 'name' in fields and not data.get('name',False): + data['name'] = msg.get('from','') + res_id = model_pool.create(cr, uid, data, context=context) attachments = msg.get('attachments', {}) self.history(cr, uid, [res_id], _('receive'), history=True, @@ -109,8 +106,6 @@ class email_thread(osv.osv): if not model: model = self._name model_pool = self.pool.get(model) - if hasattr(model_pool, 'message_update'): - model_pool.message_update(cr, uid, ids, msg, vals=vals, default_act=default_act, context=context) attachments = msg.get('attachments', {}) self.history(cr, uid, ids, _('receive'), history=True, subject = msg.get('subject'), @@ -183,16 +178,17 @@ class email_thread(osv.osv): for thread in threads: attachments = [] - for attachment in attach: - data_attach = { - 'name': attachment[0], - 'datas': binascii.b2a_base64(str(attachment[1])), - 'datas_fname': attachment[0], - 'description': _('Mail attachment'), - 'res_model': thread._name, - 'res_id': thread.id, - } - attachments.append(att_obj.create(cr, uid, data_attach)) + if attach: + for fname, fcontent in attach.items(): + data_attach = { + 'name': fname, + 'datas': binascii.b2a_base64(str(fcontent)), + 'datas_fname': fname, + 'description': _('Mail attachment'), + 'res_model': thread._name, + 'res_id': thread.id, + } + attachments.append(att_obj.create(cr, uid, data_attach)) partner_id = hasattr(thread, 'partner_id') and (thread.partner_id and thread.partner_id.id or False) or False if not partner_id and thread._name == 'res.partner': @@ -305,7 +301,6 @@ class email_thread(osv.osv): email_message_pool = self.pool.get('email.message') res_id = False - # Parse Message # Warning: message_from_string doesn't always work correctly on unicode, # we must use utf-8 strings here :-( @@ -316,7 +311,8 @@ class email_thread(osv.osv): # Create New Record into particular model def create_record(msg): - new_res_id = self.message_new(cr, uid, msg, context=context) + if hasattr(model_pool, 'message_new'): + new_res_id = model_pool.message_new(cr, uid, msg, context=context) if custom_values: model_pool.write(cr, uid, [res_id], custom_values, context=context) return new_res_id @@ -340,7 +336,8 @@ class email_thread(osv.osv): if res_id: res_id = int(res_id) if model_pool.exists(cr, uid, res_id): - self.message_update(cr, uid, [res_id], msg, {}, context=context) + if hasattr(model_pool, 'message_new'): + model_pool.message_update(cr, uid, [res_id], msg, {}, context=context) if not res_id: res_id = create_record(msg) diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index 11e76f142a1..7d58bd77d36 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -395,9 +395,23 @@ class project_issue(crm.crm_case, osv.osv): if res: vals.update(res) context.update({'state_to' : 'draft'}) - res = self.create(cr, uid, vals, context=context) - self.convert_to_bug(cr, uid, [res], context=context) - return res + + res_id = self.create(cr, uid, vals, context) + + attachments = msg.get('attachments', []) + self.history(cr, uid, [res_id], _('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 = attachments, + email_date = msg.get('date'), + context = context) + self.convert_to_bug(cr, uid, [res_id], context=context) + return res_id def message_update(self, cr, uid, ids, msg, vals=None, default_act='pending', context=None): """ diff --git a/addons/project_mailgate/project_mailgate.py b/addons/project_mailgate/project_mailgate.py index 29c813b5d8a..212fe161094 100644 --- a/addons/project_mailgate/project_mailgate.py +++ b/addons/project_mailgate/project_mailgate.py @@ -52,7 +52,22 @@ class project_tasks(osv.osv): res = thread_obj.get_partner(cr, uid, msg_from) if res: data.update(res) - return self.create(cr, uid, data) + res_id = self.create(cr, uid, vals, context) + + attachments = msg.get('attachments', []) + self.history(cr, uid, [res_id], _('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 = attachments, + email_date = msg.get('date'), + context = context) + + return res_id def message_update(self, cr, uid, id, msg, data={}, default_act='pending'): thread_obj = self.pool.get('email.thread')