Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
8525 Vizualizări

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

 

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

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")

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

XML

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

Thanks



Imagine profil
Abandonează
Cel mai bun răspuns

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"?>
<odoo>
    <data>
        <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">
                <header>
                    <!-- 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.

Regards,
Yenthe

Imagine profil
Abandonează