[IMP] mail: improvement for message_new() and related modules
bzr revid: rha@tinyerp.com-20110420060605-7q1z5917g1b7wapw
This commit is contained in:
parent
f376b23ae6
commit
7ed0659f6e
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue