Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
4931 Visualizzazioni

Odoo 14 E


When creating a Customer Invoice and adding invoice lines, I have programmed it so that the Analytic Account is set based on the customer when the line is created.

After the method sets the analytic_account_id, I want to prevent the user from editing it to anything else.

When I try to make the field "readonly" it prevents any writing to it.   I want it to be readonly after setting it so it can't be changed from what the above sets it to.

Any ideas?



Avatar
Abbandona
Risposta migliore

Hello,

    You can add 'attrs' on relevant field as below:

                 attrs="{'readonly': [('id', '!=', False)]}

Avatar
Abbandona
Autore

This is what I tried. Unfortunately, when I do this, and try to save the record, I get the error: "The record has been modified, your changes will be discarded. Do you want to proceed?"

Then it will not save with the value I assigned.

Autore

And after I corrected that, it simply won't prevent editing. When I do it from .py level it won't save it.

Autore Risposta migliore

What I needed was:  readonly="True" force_save="True"

Avatar
Abbandona
Risposta migliore

Hi,

In your xml view of that field , please try with the below code.

< field name="analytic_account_id" attrs="{'readonly' : [('analytic_account_id', '!=', False)] }" / >

Thanks

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
dic 23
90706
1
set 15
8824
4
apr 25
4790
3
lug 23
5593
2
mar 22
10381