İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

Make entire form read only Odoo 14

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
2 Cevaplar
7069 Görünümler
Avatar
Alberto
So I have a model with few fields and one of them is boolean representing locked state.

If it's locked then fields can't be edited in the forms and vice-versa.


It is currently working but I'm looking for better solution.


Currently in my form I have to declare EACH field with:

field name="example" attrs="{'readonly':[('locked','=',True)]}"


Which is working but not really nice. I tried to lock the entire form:

group attrs="{'readonly':[('locked','=',True)]}"

notebook attrs="{'readonly':[('locked','=',True)]}"

which would be better than doing it on dozen of fields but it seems that it's not having effect.


Also I don't like that this is in form level, it should be at model level but I don't know any way of doing this except declaring:

state = fields.Selection([('locked', 'Locked'), ('unlocked', 'Unlocked')], 'State', default="unlocked")

and then each model field having kwarg:

states={'lost': [('readonly', True)]}


So my question:

Can I make model field readonly without relying on the state selection field? (I would prefer it to be a boolean).

If above isn't viable then is there a way to make entire form readonly?
0
Avatar
Vazgeç
Avatar
RPM IT Services
En İyi Yanıt

Hi FarFarAway,

You need to use of fields_view_get() method which is basically loaded every time when the view is loaded.
The thing to be careful when using this method is that we can not get any data related to the respective record inside this method as it is called when loading the view (at that time, the data of the record is not loaded).

Please check the below code:
#Don't forget to import these before executing this code.
from lxml import etree
import simplejson #If not installed, you have to install it by executing pip install simplejson

@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
res = super(TestModel, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if self.env.context.get('make_form_readonly'): # Check for context value
doc = etree.XML(res['arch']) #Get the view architecture of record
if view_type == 'form': # Applies only if it is form view
for node in doc.xpath("//field"): #Get all the fields navigating through xpath
modifiers = simplejson.loads(node.get("modifiers")) #Get all the existing modifiers of each field
modifiers['readonly'] = True #Add readonly=True attribute in modifier for each field
node.set('modifiers', simplejson.dumps(modifiers)) #Now, set the newly added modifiers to the field
res['arch'] = etree.tostring(doc) #Update the view architecture of record with new architecture
return res




I hope, you have understood all the codes :)
The above code is similar to adding read-only in each field in the form view but in a cleaner way.

Regards,

RPM IT SERVICES


1
Avatar
Vazgeç
Avatar
Alberto
Üretici En İyi Yanıt

Oh God I need 8 karma just to reply to a answer on MY question ... facepalm

And can't seem to find a way to tag @RPM IT Services , this forum is incredibly bad made and this isn't the first stupid issue I had.


Anyway I'm replying to RPM IT Services, thank you for your answer but imo that is just more complicated, but more dynamic, way of just marking each field in the form as readonly manually. My goal is to have something simple and readable.


For now I've resulted in using readonly state field with locked/unlocked states and then generating 

states={'lost': [('readonly', True)]} for each model field.

0
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

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

Üye Ol
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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