我们刚从odoo 9升级到 odoo 11 。 odoo 11删除了报告打印功能,这意味着我使用的旧代码:
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])
现在已弃用。
我该如何在odoo 11中以编程方式下载报告
答案 0 :(得分:0)
所以这根本不是最好的方法,虽然有点破解,但是我通过以下方式解决了它:
使用python 请求和 lxml 程序包发出请求,手动登录odoo站点,然后进行该会话,下载所需的各种PDF。
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)