Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Odoo[12]: How to make Many2one field readonly for particular user.

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
many2onereadonlyodoo12.0
5 Răspunsuri
7161 Vizualizări
Imagine profil
Kiran

Hii

see my code below.

add_field.py

class CrmLead(models.Model):
    _inherit = 'crm.lead'

    add_portal_id = fields.Many2one('add.portal')

class AddPortal(models.Model):
    _name = "add.portal"
    _description = "Add Portal"
    _rec_name = "add_portal_name"

    add_portal_name = fields.Char(string='Add Portal Name', required=True)

add_field_view.xml

<record id="profile_field_form_inherit" model="ir.ui.view">
    <field name="name">Add Profie Field</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
    <field name="arch" type="xml">
        <field name="team_id" position="after">
            <field name="add_portal_id" string="Portal Name"/>
        </field>
    </field>
</record>

0
Imagine profil
Abandonează
Sehrish

The need of this post is, to sometime we need to visible invisible, readonly etc some filed on the basis of login user group or we want to perform some action on the basis of login user. To do so we need to get login user group: https://goo.gl/Ts3qqK

Sehrish

How to visible and invisible fields in odoo: https://goo.gl/BCxCpk

Imagine profil
Gokulakrishnan Murugesan
Cel mai bun răspuns

Hi  Kiran,

You can achieve this by using following code

In Python

from lxml import etree
@api.model
def fields_view_get(self, view_id='you_form_view_id', view_type='form', toolbar=False, submenu=False):
res = super(ClassName, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
doc = etree.XML(res['arch'])
if self.env.user.has_group('group1'):
for node in doc.xpath("//field[@name='field1']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
elif self.env.user.has_group('group2'):
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field3']"):
node.set('modifiers', '{"readonly": true}')
res['arch'] = etree.tostring(doc)
return res

You need to assign that user to specific Group based on that group you can achieve that easily

Othewise based on Login also, you can achieve

Thanks

0
Imagine profil
Abandonează
Kiran
Autor

Hi @Gokulakrishnan

i used this above code but error are occurred you can see below error

NameError: name 'TrailQueue' is not defined

how to define TrailQueue tell me

Thanks In advanced

Gokulakrishnan Murugesan

Hi KIran,

That's Class name of the Method.

Imagine profil
Nikhil Dhiman
Cel mai bun răspuns

Hi if you want to make the field readonly for a particular group, say for all the users present in a group.. you can use fields view get function to make the field readonly for a particular user.. or you can create your own record rules... 

There is another alternative, you can create a boolean field and make it invisible.. use compute function to make the field True/False based on the user logged in using self.id .... you can then use this boolean field in attrs for your field...

<field name="add_portal_id" attrs="{'readonly': [('your_boolean_field', '=', True)]}"/>

0
Imagine profil
Abandonează
Imagine profil
Ravi Gadhia
Cel mai bun răspuns

Here attrs will not work for the dynamic domain so (maybe only) option is passed context from the action and eval it on the field

like pass 'readonly_user' key from action context base on a particular user and

            <field name="add_portal_id"  string="Portal Name" readonly="context.get('readonly_user', False)"/>
​

0
Imagine profil
Abandonează
Kiran
Autor

Hello @Ravi you told that pass the 'readonly_user' key means their will be put the user's username or what plz tell me clearly.

thanks

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

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to search in many2one with selection widget applied to the field? Rezolvat
many2one odoo12.0
Imagine profil
Imagine profil
1
apr. 19
10670
How to make a field editable only if another field is filled Rezolvat
readonly odoo12.0
Imagine profil
Imagine profil
1
feb. 19
6386
Remove external conection from many2one field on form view. How to do that? Rezolvat
many2one Widgets odoo12.0
Imagine profil
Imagine profil
1
mar. 22
12481
Refresh a view form with many2one relation. How to achieve that?
many2one refresh odoo12.0
Imagine profil
Imagine profil
1
sept. 21
6306
Check condition based on a child field from a related many2one field on form view Rezolvat
many2one form_view odoo12.0
Imagine profil
Imagine profil
Imagine profil
3
ian. 20
7491
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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