Home Blog How to Show Record on Odoo Portal (My Account)
How to Show Record on Odoo Portal (My Account)

How To Show Record On Odoo Portal (My account)

Odoo was originally known as OpenERP, and it was rebranded to Odoo to show its expanded capability beyond ERP. Odoo is a powerful and customizable open-source ERP (Enterprise Resource Planning) software that streamlines the business needs and gives them the flexibility to extend their business to another level.

Odoo gives a wide range of solutions to the organizations across different industries and for various functionalities, such as HR, Sale, Purchase, Manufacturing, E-learning, E-commerce and many more.

In this blog we are going to show a custom model record on Portal (My Account)

Odoo has a powerful feature that allows users to display records in the “My account” section in the portal. In this blog we will guide you through the process of showing records in the “My account” section. 

As you can see in the below image we have sections of multiple model’s records like sale order, purchase order etc with a number of records present.

Step-by-step guide to accessing records in Odoo portal

After that  whenever we click on any of the sections, we will see a list/tree like view of all the records of that model. 

Step-by-step guide to accessing records in Odoo portal

So in this blog we are going to create same type of pages for our custom model to show record on Portal (My account)

To begin with, create a new file to manage the necessary code modifications, to show record on “My account” section

 I have created a xml file and have written the below code to show the block to get all the related record

And called the file in __manifest__.py file


<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="portal_my_home_scheduled_meetings" name="Scheduled Meetings" inherit_id="portal.portal_my_home" customize_show="True" priority="30">
        <xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
            <t t-call="portal.portal_docs_entry">
                <t t-set="title">Your Title</t>
                <t t-set="url" t-value="'/your/url'" />
                <t t-set="placeholder_count" t-value="record_count" />
            </t>
        </xpath>
    </template>
</odoo>

The portal_my_home template is already created in the portal, so what we need to do is just inherit that template from the portal and add our code according to our need. 

<t t-set="title">Your Title</t> : this is used to show a title

<t t-set="url" t-value="'/your/url'" /> : this is the url which will be called when we click on that section 

<t t-set="placeholder_count" t-value="record_count" />

Now lets head towards the controller, create a file and write a controller class that extends Customer Portal. This controller will handle the routing and return the retrieved records with a template to display in the “My account” section.

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

from odoo import http

from odoo.http import request

class PortalAccount(CustomerPortal):



    def _prepare_home_portal_values(self, counters):
        values = super()._prepare_home_portal_values(counters)
        domain = [('partner_id', '=', request.env.user.partner_id.id)]
        if record_count in counters:
            record_count = request.env[‘your.model’'].sudo().search_count(domain) \
                if request.env['meeting.meeting'].check_access_rights('read', raise_exception=False) else 0
            values[record_count] = record_count
        return values

In this file

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

The CustomPortal class is already existing in the portal module, and we will extend that class and write out logic there.

 The function “_prepare_home_portal_values()” is already created in the Portal module, we have just inherited it. This function helps us to give a number of records according to our given domain. And it will show on the section.

In the below image you can see we have added our custom model section with the help of above code.

Step-by-step guide to accessing records in Odoo portal

To create a list like view in portal we have added a sample template below.

<template id="your_template_name" name="My Records">
        <t t-call="portal.portal_layout">
            <t t-set="breadcrumbs_searchbar" t-value="True" />
            <t t-call="portal.portal_searchbar">
                <t t-set="title">Meetings</t>
            </t>
            <t t-if="not meetings">
                <p>There are currently no meetings for your account.</p>
            </t>
            <t t-if="meetings" t-call="portal.portal_table">
                <thead>
                    <tr class="active">
                        <th class="text-center">Meeting#</th>
                        <th class='text-center'>Start Time</th>
                        <th class="text-center">End Time</th>
                        <th class="text-center">Building</th>
                        <th class="text-center">Room</th>
                    </tr>
                </thead>
                <tbody>
                    <t t-foreach="meetings" t-as="meeting">
                        <tr>
                            <td class="text-center"><t t-esc="meeting.name" /></td>
                            <td class="text-center"><span t-field="meeting.start_time" /></td>
                            <td class="text-center"><span t-field="meeting.end_time" /></td>
                            <td class="text-center"><span t-field="meeting.building_id.name" /></td>
                            <td class="text-center"><span t-field="meeting.room_id.name" /></td>
                        </tr>
                    </t>
                </tbody>
            </t>
        </t>
    </template>

After adding the below code in the controller file, this code helps us to retrieve all the records based on a given domain and returns them with the template we want to show our record on and this will be called from the section we have created at first (Schedule Meeting).

    @http.route(['/your/url'], type='http', auth="user", website=True)
    def portal_your_url(self, **kw):
        domain = [('partner_id', '=', request.env.user.partner_id.id)]
        records = request.env[‘your.model'].sudo().search(domain)
        values = {
            'meetings': records
        }
        return request.render("module_name.your_template_name", values)

This is the list view created with the help of above xml code and this template is returned from the /your/url controller with the filtered data.

Step-by-step guide to accessing records in Odoo portal

 Subscribe our newsletter to learn more about Odoo ERP.


Ready to take your portal to the next level? Reach out to Kanak Infosystems and let our team of professionals guide you.

Contact an Odoo Expert

Get in touch wit​h us!

Protected by reCAPTCHA, Privacy Policy & Terms of Service apply.
Leave a Comment

Your email address will not be published.

Submit
Your comment is under review by our moderation team.