Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Odoo 17 Community – Hide "Private Information" tab unless it's the employee or an admin

Subscribe

Get notified when there's activity on this post

This question has been flagged
xmlformviewCommunityEditionodoo 17
3 Replies
2342 Views
Avatar
Konstantinos Kairos

Hi everyone,

I'm working on an Odoo 17 Community Edition project.

In the Employee form view (hr.employee.form), I want to hide the "Private Information" tab unless:

  • The logged-in user is viewing their own employee record, or
  • The logged-in user is an administrator.

Here's what the view looks like in XML:


<page name="personal_information" string="Private Information">

    <!-- Some private fields here -->

</page>



how can i fix it ?

0
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


You can hide the page  'Private Information' based on the condition.

Try the following.

XML

<record id="view_employee_form" model="ir.ui.view">
<field name="name">hr.employee.inherit.employee</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='personal_information']" position="attributes">
<attribute name="invisible">user_id != uid or uid.is_admin == False</attribute>
</xpath>
</field>
</record>

From UI

* Enable developer mode.

Edit the form view.

In these ways you can hide the page.


Hope it helps


1
Avatar
Discard
Konstantinos Kairos
Author

YOU ARE THE BEST !!!!!!!!!!!!!!

Avatar
Saiyed Mahedi Abbas
Best Answer

Hello,
Unfortunately, in Odoo 17 Community Edition, you cannot fully implement that logic (check if user is admin or viewing their own employee record) using XML alone.

Why Not?
  • XML views (attrs, groups, etc.) can only react to field values, not to dynamic logic like comparing current user to a record's user_id.
  • There’s no built-in XML expression like “if current user is this employee.”

For Example:
XML views don’t allow direct evaluation of expressions like: id == user_id.employee_id.id
because:

  • XML attrs only checks field values in the current record.
  • It doesn't know who the current user is unless you expose that data to the view (via a computed field).

Correct Way Using Minimal Python (with Your Insight!)



Step 1: Minimal Python Code

from odoo import models, fields


class Employee(models.Model):

    _inherit = 'hr.employee'


    is_self_or_admin = fields.Boolean(compute='_compute_is_self_or_admin')


    def _compute_is_self_or_admin(self):

        user = self.env.user

        for record in self:

            record.is_self_or_admin = (

                record.user_id.id == user.id or user.has_group('base.group_system')

            )
Step 2: Use it in XML
<odoo>

    <record id="view_employee_form_inherit_hide_private_info" model="ir.ui.view">

        <field name="name">hr.employee.form.hide.private.info</field>

        <field name="model">hr.employee</field>

        <field name="inherit_id" ref="hr.view_employee_form"/>

        <field name="arch" type="xml">


            <!-- Use xpath to locate the page by name -->

            <xpath expr="//page[@name='personal_information']" position="attributes">

                <attribute name="attrs">{'invisible': [('is_self_or_admin', '=', False)]}</attribute>

            </xpath>


        </field>

    </record>

</odoo>

Now the tab only shows if:

  • The logged-in user is the employee linked to the record, or
  • The user is an Admin


Thanks & Regards,
Saiyed Mahedi Abbas
Odoo Developer
Email:- saiyedmehdiabbas8@gmail.com




0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to make a field affected while openning the form view?
xml formview computed-fields
Avatar
0
Nov 24
1440
Odoo 10 Technical : how to change default view to form view Solved
xml technical formview
Avatar
Avatar
2
Jun 20
12042
How to remove Create and Edit… from many2one field.? Solved
xml many2one formview odoo
Avatar
Avatar
Avatar
Avatar
Avatar
8
Apr 23
73216
How to open a form with ir.action.server which executes python code Solved
python xml form formview
Avatar
Avatar
2
Jan 22
49915
Can't remove top "Save" button
xml button save formview
Avatar
Avatar
1
Dec 15
4758
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now