【问题标题】:odoo 8 xmlrpc can't write whole textodoo 8 xmlrpc 无法写入整个文本
【发布时间】:2017-12-29 05:13:56
【问题描述】:

我使用 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)

简历样本:

教育

新加坡国立大学工商管理学士

运行这个python没有错误,当我登录odoo查看字段时,只能看到最后一段:

新加坡国立大学工商管理学士

请问如何解决这个问题?

【问题讨论】:

    标签: python odoo-8 xml-rpc


    【解决方案1】:
    1. 关于你的代码

      合作伙伴 = { “名称”:名称, '简历':简历, }

      调用远程ORM create方法创建记录

      partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)

    如果 'cv' 字段是文本并且它有数据,那么它肯定会起作用。

    首先确保你的assignemnt变量有正确的数据。

    试试:

    partner = {
       'name': 'SnippetBucket.com',
       'cv': 'ERP Business Solution...',
    }
    
    partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
    

    由于这有效,请确保您的简历数据一旦填写,一切正常。

    【讨论】:

    • 感谢 Tejas Tank,如果使用您的样品,它可以工作。所以我发现我需要将我的简历附加到全文中。问题解决了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多