发票的 Odoo 7 Webkit 报告打印

Odoo 7 Webkit Report printing for Invoice

我尝试使用 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'})

我试过了,没有任何效果...:[=​​13=]

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()

我刚刚找到答案,经过多次测试:

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)