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

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
2 Replies
21911 Views
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
Discard
Dipak Shah

Please refer and try this :

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

Avatar
Sehrish
Best Answer

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
Discard
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
Author

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
Author

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.

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
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