我试图对一个字段实施约束
但它不会导致约束验证,而是允许保存记录而不显示任何约束消息
def _check_contact_number(self, cr, uid, ids, context=None):
for rec in self.browse(cr, uid, ids, context=context):
if rec.contact_number:
size=len(str(rec.contact_number))
if size<10:
return False
if not contact_number:
return {}
contact_number = rec.contact_number.replace('.','')
#removes any '.' from the string
contact_number = rec.contact_number.replace(' ','')
#removes space from the string
if not contact_number.isdigit():
return False
return {}
_constraints = [
(_check_contact_number, 'Enter valid phone number...!',
['contact_number']),
]
请任何人纠正我。非常感谢
这段代码有一个难看的缩进。或许这就是原因。
正确的身份看起来像这样:
def _check_contact_number(self, cr, uid, ids, context=None):
for rec in self.browse(cr, uid, ids, context=context):
if rec.contact_number:
size=len(str(rec.contact_number))
if size<10:
return False
if not contact_number:
return {}
contact_number = rec.contact_number.replace('.','')
#removes any '.' from the string
contact_number = rec.contact_number.replace(' ','')
#removes space from the string
if not contact_number.isdigit():
return False
return {}
_constraints = [
(_check_contact_number, 'Enter valid phone number...!', ['contact_number']),
]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)