odoo 11更改为从odoo 9报告渲染器

问题描述 投票:0回答:1

我们刚刚从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 odoo odoo-9 odoo-11
1个回答
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)

© www.soinside.com 2019 - 2024. All rights reserved.