odoo 11 从 odoo 9 更改为报告渲染器
odoo 11 changes to report renderer from odoo 9
我们刚刚从 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 中以编程方式下载报告
所以这根本不是最好的方法,而且有点麻烦,但我通过以下方式解决了它:
使用python requests 和 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)
我们刚刚从 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 中以编程方式下载报告
所以这根本不是最好的方法,而且有点麻烦,但我通过以下方式解决了它:
使用python requests 和 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)