콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
5209 화면

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

아바타
취소
관련 게시물 답글 화면 활동
3
12월 23
91232
1
9월 15
9021
4
8월 25
5579
3
7월 23
5814
2
3월 22
10614