0

我是odoo和python的新手。我正在开发一个模块,我需要通过从“.xml”文件中调用一个方法来隐藏一个按钮,函数定义和主体在“.py”文件中。目前正在尝试隐藏这样的按钮

<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)]}"/>

并且“start_button”列在“.py”文件中,代码类似

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),
}

并且该 python 代码在名为“OeHealthLabTests”的类中。创建实验室时显示错误

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

我很困惑,我还没有找到实现它的方法。请指导我该怎么做。

谢谢你

4

1 回答 1

1

您收到错误是因为您尚未在 xml 中定义您的字段函数。只需在 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"/>

希望我的回答能帮到你:)

于 2016-02-02T13:07:35.327 回答