Enable Dark Mode!
how-to-add-search-menu-in-customer-portal-odoo-16.jpg
By: Ranjith R

How to Add Search Menu in Customer Portal Odoo 16

Technical Odoo 16

By selecting My Account, you may access your portal account and carry out user documents such as sale orders, purchase orders, and invoices.

A count of each activity you perform inside the built module for which the portal has been constructed is also provided by the portal menu.

How to Add Search Menu in Customer Portal Odoo 16-cybrosys

When we click on these custom menus, the records will be displayed.

When we want to create a custom menu on the website, please refer to the blog : 

How to Add a Custom Menu in the Customer Portal of Odoo 16.

This blog post will explain how to add a search to a custom menu and how to show records in it.

Create an XML template that shows records in the custom menu:      

<template id =”portal_employee_payslips” name=”Payslips”>
       <t t-call=”portal.portal_layout”>
            <t t-set=”breadcrumbs_searchbar” t-value=”True”/>
            <t t-call=”portal.portal_searchbar”>
                 <t t-set=”title”>Payslips</t>
           </t>
            <t t-if=”payslip_id” t-call=”portal.portal_table”>
                   <thead>
                            <tr class=”active”>
                            <th>Reference</th>
                            <th class=”text-end”>Payslip Name</th>
                            <th class=”text-end”>Structure</th>
                        </tr>
                 </thead>
                       <t t-foreach=”payslip_id” t-as=”value”>
                           <tr>
                                 <td class=”text-end”>
                                       <span t-field=”value.number”/>
                                  </td>
                                    <td class=”text-end”>
                                       <span t-field=”value.name”/>
                                    </td>
                                      <td class=”text-end”>
                                       <span t-field=”value.struct_id”/>
                                      </td>
                           </tr>
           </t>
</template>
The template extends another template called” portal.portal_layout” using the t-call attribute.
The Python function will be displayed  as :
@http.route([‘/my/payslip’], type=”http”, auth=”user”, website=True)
def portal_my_payslip(self)
       payslip_id = request.env[“hr.payslip”].sudo().search([(“employee_id.user_id”, “=”,                 request.env.user.id)])
       return http.request.render(“module_name.portal_employee_payslips”,{“payslip_is” : payslip-id})
This is what the template looks like:

How to Add Search Menu in Customer Portal Odoo 16-cybrosys

Next, we are going to discuss how searching is done in the customer portal.

For that, we want a Python file including :

*def portal_my_payslip(self, search=””, search_in=”All”)
Portal_my_payslip takes 2 parameters search and search_in.
search is a parameter that represents the search term. It is an empty string by default.
search_in is a parameter that indicates the scope of the search. It is set to “All” by default.
*searchbar_inputs = {
   “All”: {“label” : “All”, “input”: “All”, “domain”: []},
   “Structure”: {“label” : “Structure”, “input”: “Structure”, “domain”: [(“struct_id”, “like”, search)]},

Label: Represents the display label for the search option

Input: Represents the value used for the input related to this search option

Domain: This represents a domain filter to be applied when searching

*search_domain = searchbar_inputs[search_in][“domain”]
*payslip_id = request.env[“hr.payslip”].sudo().Search([(“employee_id.user_id”, “=”, request.env.user.id)])
*payslip_id = payslip.Search(search_domain)
*return http. request.render(“module_name.portal_employee_payslips”,
                                                        {“payslip_id”: payslip-id,
                                                          “search”: search,
                                                           “search_in”: search_in})

Add these parameters to the return. The search will look like

How to Add Search Menu in Customer Portal Odoo 16-cybrosys

The search functionality in the Odoo portal document module provides users with a convenient and efficient way to locate specific documents within their organization. With this feature, users can easily search for documents based on keywords, titles, descriptions, or tags.


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