我使用python-docx来解析docx文件,然后使用xmlrpc将内容写入odoo res.partner。这是我的代码:
# -*- coding: utf-8 -*-
from os import listdir
from os.path import isfile, join
from docx import Document
import xmlrpclib
username = 'admin' #the user
pwd = 'password' #the password of the user
dbname = 'odoo8_win' #the database
# OpenERP Common login Service proxy object
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
#replace localhost with the address of the server
# OpenERP Object manipulation service
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
mypath="D:\py_test_files"
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
#open doc
for file in onlyfiles:
cv_name = mypath + '\\' + file
name = file
document = Document(cv_name)
l = [ paragraph.text.encode('utf-8') for paragraph in document.paragraphs];
for i in l:
cv = u"".join(i.decode('utf-8'))
print cv # correct without problems
partner = {
'name': name,
'cv': cv,
}
#calling remote ORM create method to create a record
partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
cv样本:
教育
新加坡国立大学工商管理学士
运行这个python时没有错误,当我在odoo中登录检查字段时,只能看到最后一段:
新加坡国立大学工商管理学士
我可以请求帮助如何解决这个问题?
如果'cv'字段是文本并且它有数据,那么确定它将起作用。
确保您的赋值变量首先具有正确的数据。
尝试:
partner = {
'name': 'SnippetBucket.com',
'cv': 'ERP Business Solution...',
}
partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
由于这项工作,确保您的简历数据一旦填写,一切正常。