Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to make a field read-only based on group security

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
2 Réponses
21946 Vues
Avatar
maram

Hello,

I have a field named "field1",  that field should be not editable by user who has group named "Bloc fields" checked.

My test code is below:

 1/file.xml

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

    <field name="name">res.partner.form.update</field>

    <field name="model">res.partner</field>

    <field name="inherit_id" ref="base.view_partner_form"/>

    <field name="groups_id" eval="[(4,ref('custom_module.bloc_fields'))]"/>

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

    <xpath expr="//field[@name='user_id']" position="after">

        <field name="field1"/>

    </xpath>

    </field>

</record>


2/security.xml

 <record id="bloc_fields" model="res.groups">

    <field name="name">Bloc fields</field>

    <field name="comment">Enable/Disable fields</field> 

</record>


3/ir.model.access.csv

"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"

"access_res_partner_bloc_fields","res_partner bloc_fields","base.model_res_partner","bloc_fields",1,0,0,0



Result:

the field "field1" is gone, it is no longer visible but when i comment  

<!-- <field name="groups_id" eval="[(4,ref('custom_module.bloc_fields'))]"/> --> it will be displayed

0
Avatar
Ignorer
Dipak Shah

Please refer and try this :

https://www.odoo.com/forum/help-1/question/make-field-readonly-based-on-group-58921

Avatar
Sehrish
Meilleure réponse

The idea is create a computed field that checks login user gorup. And we need to visible invisible some filed on the basis of login user group or we want to perform some action on the basis of login user.

How to check login user group: http://learnopenerp.blogspot.com/2017/10/how-to-check-login-user-group-in-odoo.html

After creating computed field, use that field in your xml (to make field read-only)

<field name="your_computed_field_that_check_login_user_group" attrs="{'invisible':1}"/>
<field name="field1" attrs="{'readonly':[('your_computed_field_that_check_login_user_group','=', False)]}"/>

Get complete code and detail about how to make field readonly: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

Regards,

Sehrish

0
Avatar
Ignorer
Sehrish

Refer link for get login user group: http://learnopenerp.blogspot.com/2017/10/how-to-check-login-user-group-in-odoo.html

Refer link for making fields (visible,invisible,read-only): http://learnopenerp.blogspot.com/2017/10/how-to-check-login-user-group-in-odoo.html

Hope this helps.

maram
Auteur

Hello Sehrish,

Thanks a lot for your help but this is not a solution for what i want.

In fact, I want to based on a checked group into Settings/users and through that a field will be alterable or not(readonly) by this user.

maram
Auteur

Hello the solution is:

1/ add attrs="{'readonly':False}" to the field:

<field name="field1" widget="selection" attrs="{'readonly':False}"/>

2/Inherit the original view and do this modification:

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

<field name="name">xxx_form_specify</field>

<field name="model">xxx</field>

<field name="groups_id" eval="[(6,0,[ref('module_contain_security_group.group_security_id')])]"/>

<field name="inherit_id" ref="module_contain_original_view.original_view_id"/>

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

<data>

<xpath expr="//field[@name='field1']" position="attributes">

<attribute name="readonly">True</attribute>

</xpath>

</data>

</field>

</record>

3/Don't forget to test without admin account ==> because he can see all , he havn't limit access

Ubaid ur Rehman

@maram solution works.

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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