比较字符串二字段

时间:2012-07-21 02:37:01

标签: openerp

我只是编辑我的OpenERP,但是......我有点困惑

如何比较字段A和字段B但它不应该是相同的字符串

这是我的代码

def check_description(self, cr, uid,ids, context=None):
    field = self.browse(cr, uid, ids, context=context)
    check = True
    for field in fields:
        check = check and (not field.A==field.B)
    return check
_constraints = [(_check_description, 'Please use a different string',['Warning','Description'])]

但是......我打电话使用on_change。没有责任

请帮帮我。感谢的

1 个答案:

答案 0 :(得分:0)

我看到了你的代码但是没有标记它需要一些像下面那样的

def check_description(self, cr, uid,ids, context=None):
    for record in self.browse(cr, uid, ids, context=context):
        if record.A==record.B:
            return False
    return True
_constraints = [(_check_description, 'Please use a different string',['Warning','Description'])]

如果你继续检查更多记录,你应该在发现未匹配时立即中断循环,它将继续等待。第二件事是_constraints被触发保存记录,所以在on_change的情况下确定_constraints块不会被执行,但如果你想在on_change上使用相同的功能,你需要写on_change并触发和如果找到的值相同使用raise osv.except_osv("", "")这将在屏幕上显示正确的消息。

问候。

相关问题