This question has been flagged
2 Replies
4903 Views

I'm using a web form that sends an email which is turned into a lead. The leads don't automatically parse the email and sort the name/phone/etc. into their corresponding fields. How can I use python to create an action server that does this?

I found a python example from another thread that doesn't seem to work so far:

def parse_description(description):
  '''
   there is parse function
   It is example for parsing messages like this:

   Name: John
   Phone: +100500
  '''
  fields=['Name','Phone']
  _dict={}
  description=description.lower()
  for line in description.split('\n'):
    for field in fields:
        if field in line:
            split_line=line.split(':')
            if len(split_line)>1:
                pre_dict[field]=line.split(':')[1]
  return  dict

lead=self.browse(cr,uid,context['active_id'],context=context)
description=lead['description']
_dict=parse_description(description)
self.write(cr,uid,context['active_id'],{
                        'partner_name':_dict.get('name'),
                        'contact_name':_dict.get('name'),
                        'phone':_dict.get(u'phone'),
                        'mobile':_dict.get(u'phone')})
Avatar
Discard

Did you ever get an answer to this? I am having the same issue!

Best Answer

This does not work anymore (since 2013)
as email message is not passed into lead['description'] 

Avatar
Discard