odoo中的自动操作12.使用python代码设置值

问题描述 投票:1回答:1

我尝试从一个字段中获取文本,并通过Execute Python Code将其设置为另一个字段。

recs = record.smt
for rec in recs:
    details = pythonwhois.get_whois(rec)
    if 'No match for' in str(details):
        record.smt2='ok'
    else:
        record.smt2='denied'

错误:禁止操作码

请帮忙!

python odoo
1个回答
1
投票

对于线:

details = pythonwhois.get_whois(rec)

您正在使用未导入的外部库pythonwhois,您如何在执行中使用它。由于import语句也是不允许的,因此您不能只导入任何库。

而不是使用点运算符,尝试使用write函数。

    if 'No match for' in str(details):
        smt2='ok'
    else:
        smt2='denied'
record.write({'smt2': smt})

还要记住,record是触发动作的记录;可能无效

© www.soinside.com 2019 - 2024. All rights reserved.