We've just upgraded from odoo 9 to odoo 11. odoo 11 has had the Report printing functionality removed, meaning the old code I used of:
report = xmlrpclib.ServerProxy('{}/xmlrpc/2/report'.format('https://odoo.example.com'))
result = report.render_report(self.odooconnection1.db, self.odooconnection1.uid, self.odooconnection1.password, 'account.report_invoice', [invoice_id])
is now deprecated.
How do i go about programmatically downloading reports in odoo 11
So this isn't the best way at all, and is a bit of a hack but i solved it by:
Using the python requests and lxml packages to make a request, manually login to the odoo site and then with that session, download the various PDF's i required.
import requests
from lxml import html
def __download_report(self, invoice_ids, date_to_use):
session_requests = requests.session()
login_url = "https://odoo.example.com/web/login"
result = session_requests.get(login_url)
tree = html.fromstring(result.text)
authenticity_token = list(set(tree.xpath("//input[@name='csrf_token']/@value")))[0]
payload = {
"login": "username",
"password": "password",
"csrf_token": authenticity_token
}
result = session_requests.post(
login_url,
data = payload,
headers = dict(referer=login_url)
)
for invoice_id in invoice_ids:
filename = self.__get_file_name(invoice_id)
url = "https://odoo.example.com/report/pdf/account.report_invoice/"+str(invoice_id)
pdf = session_requests.get(
url,
stream=True
)
sys.stdout.write("\r[%s]" % filename )
sys.stdout.flush()
self.__save_report(pdf, filename, date_to_use)
def __save_report(self, report_data, filename, date_to_use):
with open(filename, 'wb') as f:
f.write(report_data.content)