odoo-如何从传入的电子邮件中获取数据到many2one和数据字段?

时间:2016-06-14 13:12:58

标签: python openerp

在申请人中我添加了以便我可以从传入的电子邮件中获取数据到特定字段(名称:phone:experience ....)但这仅适用于char类型的字段,而不适用于many2one字段作为type_id和date字段:date_candidature

def message_new(self, cr, uid, msg, custom_values=None, context=None):
    """ Overrides mail_thread message_new that is called by the mailgateway
        through message_process.
        This override updates the document according to the email.
    """
    if custom_values is None:
        custom_values = {}
    val = msg.get('from').split('<')[0]
    val1 = msg.get('from').split('<')[1]
    val2 = val1.split('>')[0]
    myString2 = msg.get('body') if msg.get('body') else ''
    phone = myString2.split('PHONE: ')[1]
    phone2 = phone.split('<br')[0]
    ecole = myString2.split('ETABLISSEMENT: ')[1]
    ecole2 = ecole.split('<br')[0]
    email = myString2.split('EMAIL: ')[1]
    email2 = email.split('<br')[0]
    dispo = myString2.split('DISPO: ')[1]
    dispo2 = dispo.split('<br')[0]
    salaire = myString2.split('REMUNERATION: ')[1]
    salaire2 = salaire.split('<br')[0]
    idcand = myString2.split('IDCANDIDATURE: ')[1]
    id2 = idcand.split('-{')[0]
    datecand = myString2.split('DATECANDIDATURE: ')[1]
    date2 = datecand.split('<br')[0]
    experience = myString2.split('EXPERIENCE: ')[1]
    experience2 = experience.split('<br')[0]
    defaults = {
        'name':  msg.get('subject') or _("No Subject"),
        'partner_name': val,
        'email_from': email2,
        'email_cc': msg.get('cc'),
        'user_id': False,
        'partner_id': msg.get('author_id', False),
        'description': myString2 or '',
        'candidat_mobile': phone2 or '',
        'candidat_ecole': ecole2 or '',
        'av2': dispo2 or '',
        'av3': salaire2 or '',
        'id_candidature': id2 or '',
        'type_id': self.browse(cr, uid, ids).type_id.write({'name': experience2}),
}
    if msg.get('priority'):
        defaults['priority'] = msg.get('priority')
    defaults.update(custom_values)
    return super(hr_applicant, self).message_new(cr, uid, msg, custom_values=defaults, context=context)

0 个答案:

没有答案