Trợ giúp


how to check button is clicked or not

Abraham Qureshi

1)I have a button. If the button pressed  i want hide that button .

2)how to check button is clicked or not in odoo12


Ảnh đại diện
Huỷ bỏ
2 Câu trả lời
Best Answer


You can just add a boolean field in the form and update the boolean field value to True once the button is clicked. You can make the boolean field to True, once you clicked the button from the corresponding function that button calls.

Then Based on this Boolean field you can hide the button using attributes.

In the Python:

check = fields.Boolean("Check")

def set_button(self):
for rec in self:
rec.check = True
# rest of the code


<button name="set_button" type="object" icon="fa-globe" 
attrs="{'invisible': [('check', '=', True)}"/>


Ảnh đại diện
Huỷ bỏ
Best Answer

Hi Tom,

You can create an extra field on your model (a boolean) to check if the button has been clicked before or not. Depending on the boolean field you can show or hide the button then. Example Python:

class YourModel(models.Model):
    _name = 'your.model'
button_clicked = fields.Boolean(string='Button clicked')
@api.multi def your_button_action(self):
# This goes off when clicking your button - do your logic here.
self.button_clicked = True

Your XML:

<?xml version="1.0" encoding="utf-8"?>
        <record id='product_section_view_form' model='ir.ui.view'>
            <field name="name">product.section.form</field>
            <field name="model">product.section</field>
            <field name="arch" type="xml">
                <form string="Product section">
                    <!-- You can for example hide the button once it is clicked like this:
                    attrs="{'invisible': [('button_clicked', '=', True)]}" 
<button name="your_button_action" string="Click here" type="object"/> </header> <sheet> <field name="button_clicked" invisible="1"/> </sheet> </form> </field> </record> </data> </odoo>

You can then check on this boolean its state in any function to see if it has been clicked or not before.


1 Bình luận
Ảnh đại diện
Huỷ bỏ
Mian Kamran