This question has been flagged
2 Replies
8135 Views

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
Discard
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
Discard
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
Discard

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