Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

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

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
xmlformviewCommunityEditionodoo 17
3 Respuestas
2366 Vistas
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
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

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
Descartar
Konstantinos Kairos
Autor

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

Avatar
Saiyed Mahedi Abbas
Mejor respuesta

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
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How to make a field affected while openning the form view?
xml formview computed-fields
Avatar
0
nov 24
1466
Odoo 10 Technical : how to change default view to form view Resuelto
xml technical formview
Avatar
Avatar
2
jun 20
12056
How to remove Create and Edit… from many2one field.? Resuelto
xml many2one formview odoo
Avatar
Avatar
Avatar
Avatar
Avatar
8
abr 23
73229
How to open a form with ir.action.server which executes python code Resuelto
python xml form formview
Avatar
Avatar
2
ene 22
49983
Can't remove top "Save" button
xml button save formview
Avatar
Avatar
1
dic 15
4761
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

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