跳至內容
選單
此問題已被標幟
2 回覆
10146 瀏覽次數

Hi,

I am a beginner in python programming,

please help me, 

how to make the button state invisible after clicking, and this is my current code :

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

@api.multi
def action_close(self):

self.write({'state_id': 'out'})
self.write({'end_time':fields.Datetime.now(self)})
return self


this image : https://drive.google.com/file/d/1UIkZE6BcWr04lbNMYdtwT-IOSvkoBkfQ/view?usp=sharing


so when the status is "Sesi Berakhir" the "Sesi Berakhir" button is gone

Thanks before :D

頭像
捨棄
最佳答案

The attribute you have passed to hide the button is wrong. You have used state_id as an attribute on the button but it should be states.

Ex:

<button name="action_close" type="object" 
string="Sesi Berakhir" states="in" class="btn-primary" />

States:

Shorthand for invisible attrs: a list of states, comma separated, requires that the model has a state field and that it is used in the view.

Makes the button invisible if the record is not in one of the listed states

Danger

Using states in combination with attrs may lead to unexpected results as domains are combined with a logical AND.

Reference: Odoo Documentation

頭像
捨棄
最佳答案

hello, try like below code in xml.

add the attrs in button tag

<button name="action_close" type="object" string="Sesi Berakhir" state_id="in" class="btn-primary" 
    attrs="{'invisible': [('state_id', '=', 'out')]}"/>
頭像
捨棄

I also have a problem, but is the edit button of the base. I want to ask about hiding the edit button after clicking the button and in a status

相關帖文 回覆 瀏覽次數 活動
1
8月 20
2688
5
12月 19
11329
4
1月 19
4302
1
1月 19
7540
7
2月 18
3674