问题描述
我的代码有什么问题?
已请求:
如果A和B为0,则显示结果= A
如果A和B不为0,则继续
如果C ID为1,则执行等式
否则,如果是另一个ID,请告诉我结果= A
其他所有都显示A
我当前拥有的(不起作用):
@api.depends('A','B','C')
def _compute_X(self):
for record in self:
if int(record.A or record.B) != 0 and int(record.C) == 1:
record.X = record.A / record.B
else:
record.X = record.A
解决方法
这取决于A
,B
,C
和X
的类型。我正在考虑它们是字符串类类型。
if int(record.A or record.B) != 0 and int(record.C) == 1:
record.X = str(int(record.A) / int(record.B))
# converting string to int while doing math operation and then converting the result to strting.
else:
record.X = record.A