简体   繁体   中英

Odoo hide show button on function call

I am new to odoo and python. I am working on a module, I need to hide a button by calling a method from ".xml" file, function definition and body is in ".py" file. Currently am trying to hide button like that

<button confirm="Are you sure you want to start the test?" name="set_to_test_inprogress" states="Invoiced" string="Start Test" type="object" class="oe_highlight"groups="oehealth.group_oeh_medical_physician,oehealth.group_oeh_medical_manager" attrs="{'invisible': [('start_button', '=', False)]}"/>

and "start_button" column is in ".py" file with code like that

def _start_test_button(self, cr, uid, ids, field_name, arg, context):
    return False

_columns = {
    'start_button': fields.function(_start_test_button, type="boolean", obj="generic.request", method=True),
}

and that python code is in class named "OeHealthLabTests". When create a lab it shows error which is

Uncaught Error: Unknown field start_button in domain [["start_button","=",false],["state","not in",["Invoiced"]]]

Am confused and i didn't find a way yet to make it happen. Please guide me how can i do that.

Thank You

You got error because you not defined yet your field function in xml. Just define your field function in xml.

<button confirm="Are you sure you want to start the test?" name="set_to_test_inprogress" states="Invoiced" string="Start Test" type="object" class="oe_highlight"groups="oehealth.group_oeh_medical_physician,oehealth.group_oeh_medical_manager" attrs="{'invisible': [('start_button', '=', False)]}"/>
<field name="start_button" invisible="1"/>

i hope my answer help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM