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

I need to have a form where some fields are editable when the user creates the object, but not editable when the user is editing it. 

I mean:

  • When the user clicks create, the field must be editable.
  • When the user access an existing object (using a list) and clicks on edit, the field must be readonly.

 

아바타
취소
베스트 답변

A record that is not already saved once, has no id. So you can relly on that:

readonly: [('id','>',0)]

아바타
취소
작성자

Thanks, that's a good idea. Unfortunately it's always readonly, for creating and editing.

작성자

I have: 'cus_id': fields.related('quot_id', 'pr_id', 'cus_id', type="many2one", relation="bdd.customers", string="Customer", store=False, readonly="[('id','>',0)]"),

작성자

I think that the problem is that readonly is only evaluated when the object is created.

Then you can set a value in 

_defaults = {
  'new': True
}

that makes it possible to distinguish between a new record and a already created. When you overwrite the write(), you can reset the value:

def write(self, cr, uid, ids, vals, context=None):
   vals['new'] = False
   return super(res_partner_ext, self).write(cr, uid, ids, vals, context=context)

작성자

It worked. Actually I needed to implement it in create instead of write, but it works. The only that I don't like is to add a new field in the table, but it works. Thanks.

관련 게시물 답글 화면 활동
3
5월 24
10867
1
11월 24
1729
1
9월 21
9536
1
1월 24
17110
0
3월 15
3395