Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Read Only Based On Current User Login

Odebírat

Get notified when there's activity on this post

This question has been flagged
readonlycurrentuserv17
2 Odpovědi
4502 Zobrazení
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
Zrušit
Avatar
Jainesh Shah(Aktiv Software)
Nejlepší odpověď

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
Zrušit
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
Nejlepší odpověď

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
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
říj 25
1465
How to add a new Many2one field in res.config.settings? Vyřešeno
v17
Avatar
Avatar
Avatar
Avatar
4
říj 25
4107
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
zář 25
2658
How to disable Email notification - You have been assigned to Vyřešeno
v17
Avatar
Avatar
Avatar
Avatar
4
zář 25
8213
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
srp 25
1448
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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