Reputation: 107
In auto lead through incoming email I have added the code shown below that how to add body of email into description but I am getting as html format Can anybody know how to add content of the email body same as into description field.
def message_new(self, cr, uid, msg, custom_values=None, context=None):
myString = msg.get('subject', '')
myString.index('Phone:')
mobileNumber = myString[myString.index('Phone:')+6:myString.index('Phone:')+16]
if context is None:
context = {}
data = {}
if isinstance(custom_values, dict):
data = custom_values.copy()
model = context.get('thread_model') or self._name
model_pool = self.pool[model]
fields = model_pool.fields_get(cr, uid, context=context)
if 'name' in fields and not data.get('name'):
data['name'] = msg.get('subject', '')
if 'mobile' in fields and not data.get('mobile'):
data['mobile'] = mobileNumber
if 'description' in fields and not data.get('description'):
data['description'] = msg.get('body', '')
res_id = model_pool.create(cr, uid, data, context=context)
return res_id
Upvotes: 0
Views: 903
Reputation: 14768
Try out:
from openerp.tools import html2plaintext
# ...
if 'description' in fields and not data.get('description'):
data['description'] = html2plaintext(msg.get('body')) if msg.get('body') else ''
# ...
Upvotes: 1