Enable Dark Mode!
how-to-add-a-pdf-report-download-button-to-the-odoo-17-customer-portal.jpg
By: Sonu S

How to Add a PDF Report Download Button to the Odoo 17 Customer Portal

Technical

Odoo 17 introduces a comprehensive upgrade to business management software, offering a refined user interface, improved performance, and enhanced customization options. This version builds on the robust foundation of previous iterations, providing new and updated modules across various business functions such as CRM, inventory, and accounting. With advanced reporting tools and seamless integration across departments, Odoo 17 is designed to support businesses of all sizes in streamlining their operations and making data-driven decisions. Its scalability and flexibility make it an ideal choice for companies looking to enhance efficiency and adapt to evolving business needs.

The customer portal in Odoo 17 offers a secure online platform where customers can access their personal data and engage with your company's services. Through this user-friendly interface, customers can easily monitor their orders, check invoices, track deliveries, and view project tasks, among other features, depending on the specific modules you have activated.

To create a new menu in the "My Accounts" portal and set up a list/form view, you can refer to this blog How to Add Search in Customer Portal in Odoo 17.

This blog discusses how to add a PDF report download button to the Odoo 17 customer portal, either in a list view or a form view. This feature allows customers to easily download relevant documents, such as invoices or sales orders, directly from their portal interface.

In Odoo, when you click on "My Account," it opens the customer portal where various features are accessible, including purchase orders, sale orders, quotations, and more. Selecting each menu provides access to additional details, as shown in the figure below.

How to Add a PDF Report Download Button to the Odoo 17 Customer Portal-cybrosys

When clicking the Sale Orders, it will redirect to the sale order list view as shown below.

How to Add a PDF Report Download Button to the Odoo 17 Customer Portal-cybrosys

For example, to add a download button for each sale order in the list view, you can create a custom module and include the following XML code:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="portal_my_orders_inherit" inherit_id="sale.portal_my_orders">
        <xpath expr="//t[@t-foreach='orders']//tr" position="inside">
            <td class="text-end">
                <a t-att-href="'/my/order/%s?download=pdf' % order.id" class="btn btn-secondary btn-sm">
                    <i class="fa fa-download"/>
                    Download SO
                </a>
            </td>
        </xpath>
    </template>
</odoo>4

This code customizes the list view in the customer portal by inheriting the sale order list view template and adding a download button for each sale order. This allows customers to easily download their sale orders as PDFs within the list view.

Here’s how you can add a new controller for handling sale order PDF downloads in the Odoo 17 customer portal: Add controller named as portal.py

from odoo import http
from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal
class CustomPortal(CustomerPortal):
    @http.route('/my/order/<int:order_id>', type='http', auth='user')
    def portal_my_order(self, order_id, download=False, **kwargs):
        sale_order = request.env['sale.order'].sudo().browse(order_id)
        if not sale_order.exists():
            return request.redirect('/my/orders')
        if download:
            pdf, _ = request.env['ir.actions.report']._render_qweb_pdf('sale.report_saleorder', [order_id])
            pdfhttpheaders = [
                ('Content-Type', 'application/pdf'),
                ('Content-Length', len(pdf)),
                ('Content-Disposition', 'attachment; filename="%s.pdf"' % (sale_order.name)),
            ]
            return request.make_response(pdf, headers=pdfhttpheaders)
        return request.redirect(sale_order.get_portal_url())

After implementing these changes, the user interface will appear as follows:

How to Add a PDF Report Download Button to the Odoo 17 Customer Portal-cybrosys

When clicking this button, the corresponding sale order will be downloaded as a PDF, as shown in the figure below.

How to Add a PDF Report Download Button to the Odoo 17 Customer Portal-cybrosys

Using this method, you can add download buttons to both list and form views in the customer portal to allow users to download PDF reports.

Adding a PDF report download button to the Odoo 17 customer portal, whether in list or form views, greatly enhances user experience by providing immediate access to key documents like sales orders or invoices. This feature simplifies the retrieval and management of reports, making it more convenient for users to obtain necessary information directly from the portal. Customizing portal templates and setting up routes for PDF generation not only improves accessibility but also streamlines document management and reduces manual steps. As a result, customers enjoy quicker access to their documents, which can boost satisfaction and contribute to a more efficient workflow.

To read more about How to Create a PDF Report in Odoo 17?, refer to our blog How to Create a PDF Report in Odoo 17?


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message