【发布时间】:2015-09-03 06:34:14
【问题描述】:
我试图为一个字段实现一个约束 但它不会导致约束验证,而是允许保存记录而不显示任何约束消息
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']),
]
请任何人纠正我。非常感谢
【问题讨论】:
-
不是发出警告吗?
-
小心缩进。检查您的条件下方的返回语句。
标签: python odoo odoo-8 openerp-8