我通过以下代码通过收到的电子邮件定制了潜在客户。我在电子邮件中获取正文的内容并与lead中的字段匹配。模板每次都是相同的,但有时数据不会出现。 例;模板是来电者姓名:abcd 电话:1234567891 电子邮件:abcd@gmail.com 日期:16/12/16 电子邮件正文中的数据每次都是相同的,但有时电子邮件不会出现或任何其他电子邮件。电子邮件不会生成导致。我想要上面的数据将出现的情况,然后字段应该填写否则离开它。 任何人都可以帮助我如何写出这个条件
我的代码:
def message_new(self,cr,uid,msg,custom_values = None,context = None):
_logger.info(" ________________________ MESSAGE_NEW ________________________&#34)
_logger.info(msg.get(' subject',''))
#myString = msg.get('subject', '')
#myString.index('Phone:')
#mobileNumber = myString[myString.index('Phone:')+6:myString.index('Phone:')+16]
myString = html2plaintext(msg.get('body', ''))
_logger.info(myString)
myString.index('Caller Name:')
newstring=myString.split("*")
_logger.info("--------------------------------------------------------")
_logger.info(newstring)
indx=newstring.index('Caller Name:')
mobileNumber = newstring[indx+1]
indx=newstring.index('Caller\nPhone:')
mobile=newstring[indx+1]
indx=newstring.index('City:')
city=newstring[indx+1]
indx=newstring.index('Branch Info:')
branch=newstring[indx+1]
indx=newstring.index('Caller\nEmail:')
emailstr=newstring[indx+1]
emailarr=emailstr.split("[")
email=emailarr[0]
indx=newstring.index('Caller\nRequirement:')
requirement=newstring[indx+1]
indx=newstring.index('Caller\nRequirement:')
requirement=newstring[indx+1]
indx=newstring.index('Call Date &\nTime:')
date=newstring[indx+1]
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'] = requirement
if 'contact_name' in fields and not data.get('contact_name'):
data['contact_name'] = mobileNumber
if 'city' in fields and not data.get('city'):
data['city'] = city
if 'mobile' in fields and not data.get('mobile'):
data['mobile'] = mobile
if 'street' in fields and not data.get('street'):
data['street'] = branch
if 'email_from' in fields and not data.get('email_from'):
data['email_from'] = email
if 'x_date' in fields and not data.get('x_date'):
data['x_date'] = date
res_id = model_pool.create(cr, uid, data, context=context)
return res_id
答案 0 :(得分:1)
这是你的条件
如果在新闻字符串中显示'Caller \ nEmail:': if newstring.index('Caller \ nEmail:'): indx4 = newstring.index( '主叫\ nEmail:') emailstr = newstring [indx4 + 1] emailarr = emailstr.split( “[”) 电子邮件= emailarr [0] 其他: email ='' 其他: email =''