您應該添加一個on_change功能Python代碼,你是否START_TIME和END_TIME是正確的格式。而在你的xml中,你必須告訴應該在字段改變時調用該方法。
XML
<field name="start_time" on_change="check_hour_format(start_time)"/>
<field name="end_time" on_change="check_hour_format(end_time)"/>
的Python
的結果應該是這樣的
def check_hour_format(self,cr,uid,ids,time_field,context=None):
if correct format
return {}
else:
warning = {'title' : _("Warning for this value!"),
'message': _("Field not in correct format!"),
}
return {'warning': warning}
此代碼應該適用於這個問題
import time
def check_hour_format(self,cr,uid,ids,time_field,context=None):
try:
time.strptime(char_input, "%H:%M")
return {}
except ValueError:
warning = {'title' : _("Warning for this value!"),
'message': _("Field not in correct format!"),
}
return {'warning': warning}
在on_change方法,你可以改變字段值
def on_change(self, cr, uid, ids, context=None):
# do something
return {'value': { 'field_name': newValue},
'warning': {'title': _("Warning"),
'message': _("warning message")
}
}