Search code examples
pythondebianodooxmlrpclib

Odoo 7 Webkit Report printing for Invoice


I try to print invoice based on Webkit model with xmlrpclib.

The purpose is to get PDF Invoice on another server.

I have successuly done this with standard PDF report :

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'})

I try this without any effect ... :

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'})

Someone have done this before ?

Complet sample code :

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

Solution

  • I just found the answer, after many tests :

    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)