Bil*_*hab 2 python division depends odoo
我的代码有什么问题?
要求:
如果 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
Run Code Online (Sandbox Code Playgroud)
小智 5
这取决于类型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
Run Code Online (Sandbox Code Playgroud)