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

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

Technical Odoo 18

Odoo 18 introduces significant advancements in business management software, featuring an optimized user interface, enhanced system performance, and expanded customization capabilities. This latest version builds upon previous iterations, introducing improved modules across key business functions such as CRM, inventory, and accounting. With powerful analytics, seamless departmental integration, and AI-driven automation, Odoo 18 enables businesses of all sizes to optimize operations and make informed decisions. Its scalability and adaptability make it a perfect solution for companies seeking to improve efficiency and stay ahead in a dynamic market.

The customer portal in Odoo 18 serves as a secure and intuitive online platform where customers can conveniently access their personal information and interact with company services. With this streamlined interface, users can track orders, view invoices, monitor deliveries, and oversee project tasks based on the activated modules. Odoo 18 enhances the customer experience by offering greater transparency and accessibility, strengthening client relationships and engagement.

For a detailed guide on creating a new menu in the "My Account" portal and setting up a list/form view, you can refer to this blog: How to Add a Custom Menu, List View, & Filters in the Customer Portal Odoo 18.

This blog explains how to add a PDF report download button to the Odoo 18 customer portal, allowing customers to easily download important documents like invoices or sales orders from either the list view or the form view.

In Odoo, clicking on "My Account" opens the customer portal, where users can access various features such as purchase orders, sales orders, quotations, and more. Each menu selection provides further details, as illustrated in the figure below.

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

Clicking on "Our Orders" (Purchase Orders) redirects to the sales order list view, as shown in the figure below.

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

To include a download button for each purchase order in the list view, you can build a custom module and define the XML view as shown below.:

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

This code customizes the customer portal's list view by extending the purchase order template and adding a download button for each order. This enables customers to conveniently download their purchase orders as PDFs directly from the list view.

Here's how you can create a new controller to handle sales order PDF downloads in the Odoo 18 customer portal. Define the controller in a file named portal.py.

Python:

from odoo import http
from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal

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

After applying these changes, the user interface will look as follows:

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

Clicking this button will download the corresponding sales order as a PDF, as shown in the figure below.

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

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

By implementing this approach, you can seamlessly integrate download buttons into both list and form views of the customer portal, enabling users to effortlessly download PDF reports.

Enhancing the Odoo 18 customer portal with a PDF download button in either list or form views improves usability by allowing users to quickly access important documents such as sales orders, purchase orders, and invoices. This feature simplifies document retrieval and management, making it easier for users to access important information directly from the portal.

Customizing portal templates and configuring routes for PDF generation improve accessibility, streamline document handling, and minimize manual effort. As a result, customers can retrieve their documents more quickly, leading to greater satisfaction and a more efficient workflow.

To read more about how to add a PDF Report Download Button to the Odoo 17 Customer Portal, refer to our blog How to Add a PDF Report Download Button to the Odoo 17 Customer Portal.


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



0
Comments



Leave a comment



whatsapp_icon
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