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

Read Only Based On Current User Login

Suscribirse

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

Se marcó esta pregunta
readonlycurrentuserv17
2 Respuestas
4510 Vistas
Avatar
Ricky Raymond

Hi, i want to make a field become read only based on current user login.

I have field 'name' (many2one res.users) & 'checklist' (boolean)

The name is manualy choose and the checklist field is read only if the name is not the same as user id login. Is it by python in backend / by xml enough?

0
Avatar
Descartar
Avatar
Jainesh Shah(Aktiv Software)
Mejor respuesta

Hi Ricky Raymond,


In Odoo, you can achieve this requirement by using a combination of Python code and XML. You will need to define a computed field in the Python model that checks whether the current user's ID matches the value of the name field. Then, you can use this computed field in the XML view to conditionally set the readonly attribute of the checklist field.


Here's how you can implement it:


Define a computed field in the Python model to check if the current user's ID matches the name field.

Use the computed field in the XML view to conditionally set the readonly attribute of the checklist field.

Please find code in comment. 

Feel free to contact me if needed

Hope this will help you.

Thanks & Regards,
Email:   odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

0
Avatar
Descartar
Jainesh Shah(Aktiv Software)

Here's a basic example of code :-

Python (in your model file, e.g., your_model.py):

from odoo import models, api

class YourModel(models.Model):
_name = 'your.model'

name = fields.Many2one('res.users', string='Name')
check_checklist = fields.Boolean(string='Checklist', store=True, compute='_compute_checklist_readonly')
checklist = fields.Boolean(string='Checklist')

@api.depends('name')
def _compute_checklist_readonly(self):
current_user = self.env.user
for record in self:
record.check_checklist = (record.name.id == current_user.id)

XML :-

<record id="view_your_model_form" model="ir.ui.view">
<field name="name">your.model.form</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<form string="Your Model Form">
<sheet>
<group>
<field name="name" widget="many2one_avatar_user"/>
<field name="check_checklist" invisible="True"/>
<field name="checklist" readonly="not check_checklist"/>
</group>
</sheet>
</form>
</field>
</record>

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

Hi,

To implement this flow, you can add a new computed field. First, add a boolean field and set it as computed. Inside the compute function, check if the user_id field matches self.env.uid. If it matches, set the field to True; otherwise, set it to False. Then, add the readonly attribute to the field in XML using the compute field. Here's an example in Python and XML:

Python:
check_access_team_id = fields.Boolean('Check Access', compute='_compute_access_team_id')

@api.depends('user_id')
def _compute_access_team_id(self):
    for rec in self:
        rec.check_access_team_id = rec.user_id.id == self.env.uid

XML:

<field name="check_access_team_id" invisible="True"/>
<field name="user_id" widget="many2one_avatar_user"/>
<field name="team_id" readonly="not check_access_team_id"/>

In this example, the `check_access_team_id` field is computed based on whether the `user_id` matches the current user (`self.env.uid`). Then, the `team_id` field is set as readonly depending on the value of `check_access_team_id`.


Hope it helps

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
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
oct 25
1472
How to add a new Many2one field in res.config.settings? Resuelto
v17
Avatar
Avatar
Avatar
Avatar
4
oct 25
4116
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
sept 25
2666
How to disable Email notification - You have been assigned to Resuelto
v17
Avatar
Avatar
Avatar
Avatar
4
sept 25
8223
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
ago 25
1453
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