Skip to Content
Menu
This question has been flagged
2 Replies
10230 Zobrazenia

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

Avatar
Zrušiť
Best Answer

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

Avatar
Zrušiť
Best Answer

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')]}"/>
Avatar
Zrušiť

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

Related Posts Replies Zobrazenia Aktivita
1
aug 20
2786
5
dec 19
11399
4
jan 19
4398
1
jan 19
7619
7
feb 18
3762