Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4797 มุมมอง

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?



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

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

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

อวตาร
ละทิ้ง
ผู้เขียน

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.

ผู้เขียน

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

ผู้เขียน คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
readonly option in fields? แก้ไขแล้ว
3
ธ.ค. 23
90332
1
ก.ย. 15
8739
4
เม.ย. 25
4245
3
ก.ค. 23
5405
change existing field readonly แก้ไขแล้ว
2
มี.ค. 22
10266