简体   繁体   English

如何在Odoo14 Web中导出xlsx

[英]How to export xlsx in Odoo14 Web

How to export xlsx data form my/order website portal如何从我/订单网站门户导出 xlsx 数据

I added one button in sale order portal My Account -> Sales Orders page like this我在销售订单门户“我的帐户”->“销售订单”页面中添加了一个按钮,如下所示

<!-- Add the Export Button -->
<template id="portal_my_orders_inherit_export" inherit_id="sale.portal_my_orders" customize_show="True">
    <xpath expr="//t[@t-call='portal.portal_searchbar']" position="before">

        <button class="btn btn-primary mb-2 sale_export_btn_class" id="sale_export_btn_id" type="button">
            Export Sale
        </button>
    </xpath>
</template>

When i click on this button export a xlsx file with all the sale order of the logged user当我单击此按钮时,导出一个 xlsx 文件,其中包含已登录用户的所有销售订单

Please help me to resolve this.请帮我解决这个问题。

Thank you.谢谢你。

The xlsx report its a controller you should call it from your button or create a widget that response to your onClick event button to call the controller and return the response to the browser with the report inside it. xlsx 报告它的 controller 您应该从按钮调用它或创建一个响应您的onClick事件按钮的小部件来调用 controller 并将响应返回给浏览器内部的报告。

I hope this answer can be helpful for you.我希望这个答案可以对你有所帮助。

You can use a <a> tag and define a controller function to render and download the XLSX report.您可以使用<a>标记并定义 controller function 来呈现和下载 XLSX 报告。

In the following, we suppose you already created an XLSX report using the report_xlsx module在下文中,我们假设您已经使用report_xlsx模块创建了一个 XLSX 报告

Example:例子:

<a role="button" t-if="orders"
   t-att-href="'/my/export_orders?order_ids=%s' % orders.ids"
   class="btn btn-primary mb-2 mt-2"
   target="_blank"
>

Alter the customer portal controller to define the /my/export_orders route更改客户门户 controller 以定义/my/export_orders路由

class CustomerPortalExtended(CustomerPortal):
    @http.route('/my/export_orders', type='http', auth="user", website=True)
    def export_orders(self, **kw):
        order_ids = ast.literal_eval(kw['order_ids'])
        report_sudo = request.env.ref(report_name).with_user(SUPERUSER_ID)
        report = report_sudo._render_xlsx(order_ids, {})[0]
        report_http_headers = [
            ('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
            ('Content-Length', len(report)),
            ('Content-Disposition', content_disposition("Orders.xlsx"))
        ]
        return request.make_response(report, headers=report_http_headers)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM