通过下面的函数,我试图确定一个列是否已经有X值。在
def error_verify(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids, context):
nr = int(record.nr_service) # Gets the current value from field
cr.execute("SELECT nr_service FROM services WHERE nr_service = %s", [nr])
values = cr.fetchall()
if values: # if there's ANY result it means there's at least one
# row with that value in the table
return True
return False
函数的调用方式如下:
^{pr2}$问题是:我没有得到任何结果。我试图得到错误信息,但我无法到达那里。我把一些现有的值放在record.nr_服务“,但它不会抛出任何消息。我的问题是:我的功能做得对吗?在
我也试过这样做:
def error_verify(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids, context):
nr = int(record.nr_service) # Gets the current value from field
cr.execute("SELECT nr_service FROM services WHERE nr_service = %s", [nr])
values = cr.fetchall()
for n in values:
if nr == int(n[0]):
return True
return False
在这种情况下,也不会抛出任何信息。在
我该怎么解决呢?在
好吧,我一直在测试,我想我找到了我的错误所在。假设数据库中有值“3”。所以,每当我在字段中写入值“3”时,它应该会显示一条错误消息,否则它会释放我。在
这是有效的:
这也适用于:
^{pr2}$这里的问题是,我不能在查询中告诉值“3”,我应该从一个字段->OpenERP field->中获取该值,如下所示:
通过这段代码,它会检索错误消息(在第一篇文章中)不管我在字段中输入的值是多少。所以,问题一定在循环中。但我真的需要从这个字段中得到值。在
谢谢!在
解决了。在
相关问题 更多 >
编程相关推荐