gpt4 book ai didi

python - 如何在 python Odoo 中计算多个级别

转载 作者:行者123 更新时间:2023-12-02 02:33:23 26 4
gpt4 key购买 nike

我的代码有什么问题?

请求:

If A annd B are 0 show me result = A

If A and B are not 0 then continue

If C ID is 1 Do the equation

Else if it's another ID then show me result = A

Else of all just show 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

最佳答案

这取决于ABCX的类型。我正在考虑将它们视为字符串类。

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

关于python - 如何在 python Odoo 中计算多个级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64719299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com