Enable Dark Mode!
how-to-add-pagination-in-website-portal-in-odoo-17.jpg
By: Afra MP

How to Add Pagination in Website Portal in Odoo 17

Technical Odoo 17

In today's digital world, websites often need to display large amounts of content or data. However, it is not practical to showcase all the information on one page, as this can lead to a cluttered and overwhelming user experience. This is where pagination comes in. Pagination allows websites to split their content into multiple pages, giving users smoother navigation and a better user experience. In this article, we will explore how to add pagination to an Odoo website.

Understanding Pagination in Websites

Pagination is a technique used to break large pieces of content into smaller, more manageable pages. It ensures that website visitors can easily navigate through different sections or categories without feeling overwhelmed by an excessive amount of information on a single page. For example, consider an e-commerce website like Amazon. It would be impractical to display all products in a particular category on one page. Instead, Amazon uses pagination to split products across multiple pages, allowing users to browse through different pages to find what they're looking for.

Adding Pagination in Odoo Website

Odoo, a comprehensive business management software, provides built-in features to manage website pagination. By rendering the pager values in the controller, you can easily implement pagination in your Odoo website. 

In Odoo, controllers are used to organize and manage the frontend modules of a website. They allow users to render information into a site by integrating frontend and backend modules. To add pagination to your Odoo website, you need to create a controller. Here's an example of a controller that handles sale quotation listing with pagination:

class CustomerPortal(CustomerPortal):
   @http.route(['/my/quotes', '/my/quotes/page/<int:page>'], type='http',
               auth="user", website=True)
   def portal_my_quotes(self, page=1, date_begin=None,date_end=None,
                        sortby=None,**kw):
       values = self._prepare_portal_layout_values()
       partner = request.env.user.partner_id
       SaleOrder = request.env['sale.order']
       if request.env.user.has_group('base.group_portal'):
           domain = [
               ('state', 'in', [ 'sent','cancel']),
               ('partner_id', '=', partner.id)]
       else:
           domain = [
               ('message_partner_ids', 'child_of',
                [partner.commercial_partner_id.id]),
               ('state', 'in', ['sent','cancel'])]
       searchbar_sortings = {
           'date': {'label': _('Order Date'), 'order': 'date_order desc'},
           'name': {'label': _('Reference'), 'order': 'name'},
           'stage': {'label': _('Stage'), 'order': 'state'},
       }
       if not sortby:
           sortby = 'date'
       sort_order = searchbar_sortings[sortby]['order']
       quotation_count = SaleOrder.search_count(domain)
       pager = portal_pager(
           url="/my/quotes",
           url_args={'date_begin': date_begin, 'date_end': date_end,
                     'sortby': sortby},
           total=quotation_count,
           page=page,
           step=15
       )
       # search the count to display, according to the pager data
       quotations = SaleOrder.search(domain, order=sort_order,
                                     limit=15,
                                     offset=pager['offset'])
       request.session['my_quotations_history'] = quotations.ids[:100]
       values.update({
           'date': date_begin,
           'quotations': quotations.sudo(),
           'page_name': 'quote',
           'pager': pager,
           'default_url': '/my/quotes',
           'searchbar_sortings': searchbar_sortings,
           'sortby': sortby,
       })
       return request.render("sale.portal_my_quotations", values)

In the code above, we super a controller called CustomerPortal with the /my/quotes route. The portal_my_quotes method handles the logic for loading and rendering sale quotation data using pagination. Parameters like page and search are needed to process the current page and search functions. The pager variable is responsible for generating paging links based on the total number of sale quotations and the current page.

Customizing Pagination Parameters:

The Odoo website pagination feature allows you to customize various parameters according to your requirements. Let's take a look at some of the key parameters:

Url: The base URL of the page link.

Total: The total number of items to be displayed across multiple pages.

Page: The current page number.

Step: The number of items per page.

Scope: The number of pages to display in the pager.

Url_args: Additional parameters to add as query parameters to the page URL.

By adjusting these parameters in the controller, you can fine-tune the pagination behavior to suit your specific needs.

Conclusion

So , adding pagination to Odoo website is essential for enhancing user experience and improving navigation through large amounts of content. By following the steps outlined in this article, you can easily implement pagination in your Odoo website and provide your visitors with a more intuitive and organized browsing experience. Remember to customize the pagination parameters to align with your specific requirements. With pagination in place, your website will be better equipped to handle and present large volumes of data efficiently.


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