2017-12-29 5 views
0

Ich benutze python-docx, um docx-Datei zu analysieren, dann benutze xmlrpc, um Inhalt in odoo res.partner zu schreiben. Hier ist mein Code:odoo 8 xmlrpc kann nicht ganzen Text schreiben

# -*- 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 Beispiel:

Bildung

National University of Singapore Bachelor of Business Administration

Es ist kein Fehler, wenn dieser Python ausführen, wenn ich in odoo anmelden das Feld zu überprüfen, kann nur letzten Absatz sehen:

Nationale Universität Von Singapur Bachelor Of Business Administration

Darf ich um Hilfe bitten, um dieses Problem zu lösen?

Antwort

0
  1. In Bezug auf den Code

    Partner = { 'name': Name, 'cv': cv, }

    Aufruf remote ORM Methode erstellen einen Datensatz erstellen

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

Wenn 'cv' Feld ist Text und es hatte Daten, dann sicher, es funktioniert.

Stellen Sie sicher, dass Ihre zugewiesene Variable zuerst die richtigen Daten enthält.

Versuchen:

partner = { 
    'name': 'SnippetBucket.com', 
    'cv': 'ERP Business Solution...', 
} 

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

Da diese workes, sicher, wenn Sie Ihren Lebenslauf Daten gefüllt, alles funktioniert.

+1

Dank Tejas Tank, wenn Sie Ihre Probe verwenden, funktioniert es. So fand ich, dass ich meinen Lebenslauf an einen vollen Text anhängen muss. das Problem wurde gelöst. – ITGeeker