我尝试使用xmlrpclib打印基于Webkit模型的发票。
目的是在另一台服务器上获取PDF发票。
我已成功使用标准PDF报告:
printsock = xmlrpclib.ServerProxy(url+'/xmlrpc/report')
model = 'account.invoice'
id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'id': ids[0], 'report_type':'pdf'})
我试着这没有任何影响......:
printsock = xmlrpclib.ServerProxy(url+'/xmlrpc/report')
model = 'account.invoice'
id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'report_type':'webkit', 'id':866, 'webkit_header':[2,"sale order"], 'report_name':'webkit.account.invoice'})
之前有人这样做过吗?
完成示例代码:
import sys
import time
import base64
import xmlrpclib
import imp
config = imp.load_source('config', '../config/config.py')
ref_facture = sys.argv[1]
username = config.ADMIN_USER #the user
pwd = config.ADMIN_PASSWORD #the password of the user
dbname = config.DBNAME #the database
url = config.URL
# Get the uid
sock_common = xmlrpclib.ServerProxy (url+'/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
# Connection
sock = xmlrpclib.ServerProxy(url+'/xmlrpc/object')
args = [('number', '=', ref_facture)] #query clause
ids = sock.execute(dbname, uid, pwd, 'account.invoice', 'search', args)
# Service de reporting
printsock = xmlrpclib.ServerProxy(url+'/xmlrpc/report')
model = 'account.invoice'
id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'report_type':'webkit', 'id':866, 'webkit_header':[2,"sale order"], 'report_name':'webkit.account.invoice'})
time.sleep(5)
state = False
attempt = 0
while not state:
report = printsock.report_get(dbname, uid, pwd, id_report)
state = report['state']
if not state:
time.sleep(1)
attempt += 1
if attempt>200:
print 'Printing aborted, too long delay !'
string_pdf = base64.decodestring(report['result'])
file_pdf = open('/tmp/facture.pdf','w')
file_pdf.write(string_pdf)
file_pdf.close()
答案 0 :(得分:0)
经过多次测试后,我才找到答案:
context = {'lang': 'fr_FR'}
id_report = printsock.report(dbname, uid, pwd, model, ids, {'model': model, 'report_type':'webkit', 'id':id_of_report, 'webkit_header':[id_of_webkit_header,"name_of_webkit_header"], 'report_name':'webkit.account.invoice', 'lang':'fr_FR','tz':'Europe/Paris'}, context)