[英]Odoo hide show button on function call
我是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"]]]
很困惑,我還沒有找到實現它的方法。 請指導我該怎么做。
謝謝
您收到錯誤消息是因為尚未在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"/>
希望我的回答對您有所幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.