Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

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

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
many2onereadonlyodoo12.0
5 Risposte
7158 Visualizzazioni
Avatar
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
Avatar
Abbandona
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

Avatar
Gokulakrishnan Murugesan
Risposta migliore

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
Avatar
Abbandona
Kiran
Autore

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.

Avatar
Nikhil Dhiman
Risposta migliore

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
Avatar
Abbandona
Avatar
Ravi Gadhia
Risposta migliore

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
Avatar
Abbandona
Kiran
Autore

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

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
How to search in many2one with selection widget applied to the field? Risolto
many2one odoo12.0
Avatar
Avatar
1
apr 19
10663
How to make a field editable only if another field is filled Risolto
readonly odoo12.0
Avatar
Avatar
1
feb 19
6386
Remove external conection from many2one field on form view. How to do that? Risolto
many2one Widgets odoo12.0
Avatar
Avatar
1
mar 22
12478
Refresh a view form with many2one relation. How to achieve that?
many2one refresh odoo12.0
Avatar
Avatar
1
set 21
6302
Check condition based on a child field from a related many2one field on form view Risolto
many2one form_view odoo12.0
Avatar
Avatar
Avatar
3
gen 20
7490
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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