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

Hi,

I need help to make one2many field be readonly when button clicked.
this my code ;

<form string="Sesi Parkir">
	<header>
		<button name="action_close" type="object" string="Sesi Berakhir" states="in" class="btn-primary" />
		<field name="state" widget="statusbar" statusbar_visible="in,out"/>
	</header>

parking_log_ids=fields.One2many('parking_log','parking_log_id',string='Log Parkir')
@api.multi def action_close(self): self.write({'state': 'out'}) self.write({'end_time':fields.Datetime.now(self)}) self.write({'parking_log_ids':'readonly=True'}) # i try like this but nothing happen :v

when I click the 'action_close' button, the one2many field becomes readonly and cannot add the record again

Thanks before :D
아바타
취소
베스트 답변

Hi Fazryan,

Why don't you simply add a domain in the XML view depending on the state for example? I see you move the state to 'out' and fill in an 'end_time' so you can do it depending on that:

<field name="parking_log_ids" attrs="{'readonly': ['&amp;', ('state', '=', 'out'), ('end_time', '!=', False)]}"/>

Regards,
Yenthe

아바타
취소
작성자

Hello Yenthe, thanks for response.

i implementation your code but still can 'add item'

even though the session status has ended

see this image ; https://drive.google.com/file/d/163ZqYsFbosgB0tgZ3Ve-Qdokd4kmSqoP/view?usp=sharing

작성자

the point is i want is when status has ended, one2many field cannot 'add an item'

베스트 답변

hello,

your py code something like 

@api.multi
def action_close(self):
self.write({'state': 'out', 'end_time':fields.Datetime.now()})

into xml add code like

<field name="parking_log_ids" attrs="{'readonly': [('state', '=', 'out')]}">   
 <tree>
        <field name="your_fieldname"/>
  </tree>
</field>
아바타
취소
관련 게시물 답글 화면 활동
1
8월 20
2829
5
12월 19
11536
1
1월 19
7706
2
1월 19
10318
7
2월 18
3792