Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Sociale media-marketing
    • E-mailmarketing
    • Sms-marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Make entire form read only Odoo 14

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
2 Antwoorden
7075 Weergaven
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
Annuleer
Avatar
RPM IT Services
Beste antwoord

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
Annuleer
Avatar
Alberto
Auteur Beste antwoord

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
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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