【发布时间】:2016-06-20 10:43:14
【问题描述】:
我通过以下代码通过传入的电子邮件自定义了潜在客户生成。我正在获取电子邮件中的正文内容并匹配潜在客户中存在的字段。模板每次都相同,但有时数据不会出现。 例子;模板是来电者姓名:abcd 电话:1234567891 电子邮件:abcd@gmail.com 日期:16/12/16 电子邮件正文中的数据每次都是相同的,但有时电子邮件不会出现或任何其他。电子邮件不会生成引导。我希望上述数据将出现然后该字段应填写否则离开它的条件。 有人帮我写那个条件
我的代码:
def message_new(self, cr, uid, msg, custom_values=None, context=None):
_logger.info("________________________MESSAGE_NEW________________________")
_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
【问题讨论】:
标签: python-2.7 openerp odoo-8 openerp-8 odoo-9