我还在学习Openerp,如果我问一些非常简单的事情,请耐心等待。 我的问题是我需要验证两个代表start_time和end_time的字段。
这两个字段都在char
中'start_time': fields.char('Start Time'),
'end_time': fields.char('End Time'),
我需要做的是,一旦用户输入此start_time和end_time,我需要检查该输入是否在24小时内以及 hh:mm 模式。
请善待我帮助
答案 0 :(得分:2)
您应该在python代码中添加一个on_change函数,检查start_time和end_time是否格式正确。在您的xml中,您必须告诉该字段在字段更改时应该调用该方法。
<强> XML 强>
DECLARE
x XMLType := XMLType(
' <changeRequest customerRequestRef="" BTProjectManagementRef="">
<customerOrganisation orgID="ID000001" orgInternalID="29823" resignInstanceType="Source">
<organisationName>BT PLC</organisationName>
<contactInfo contactID="ID000002">
<role>CUSTOMER</role>
<position />
<fullName />
<telephone />
<fax />
<email />
<contactAddress>
<room />
<floor />
<building />
<streetNumber />
<streetName />
<locality />
<city />
<county-state />
<country ISOCountryCode="" />
<postcode />
</contactAddress>
</contactInfo>
</customerOrganisation>
<customerOrganisation orgID="ID000003" orgInternalID="29823" resignInstanceType="Target">
<organisationName>BT PLC</organisationName>
<contactInfo contactID="ID000004">
<role>CUSTOMER</role>
<position />
<fullName />
<telephone />
<fax />
<email />
<contactAddress>
<building />
<streetNumber />
<streetName />
<city />
<county-state />
<country />
<postcode />
</contactAddress>
</contactInfo>
</customerOrganisation>
</changeRequest>');
BEGIN
For R In (
SELECT EXTRACTVALUE(Value(p),'/customerOrganisation/contactInfo/role/text()') as role,
EXTRACTVALUE(Value(p),'/customerOrganisation/contactInfo/position/text()') as position,
EXTRACTVALUE(Value(p),'/customerOrganisation/contactInfo/@contactID') as contactID
FROM TABLE(XMLSequence(Extract(x,'/changeRequest/customerOrganisation'))) p
) LOOP
dbms_output.put_line(r.role || ' ' || r.position || ' ' || r.contactID);
End Loop;
Exception
When Others then
dbms_output.put_line(sqlerrm);
END;
<强>的Python 强>
结果应该是
<field name="start_time" on_change="check_hour_format(start_time)"/>
<field name="end_time" on_change="check_hour_format(end_time)"/>
此代码适用于此问题
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}
在on_change方法中,您可以更改字段值
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}