【问题标题】:How to compute multiple levels in python Odoo如何在 python Odoo 中计算多个级别
【发布时间】:2020-11-06 17:42:29
【问题描述】:

我的代码有什么问题?

请求:

如果 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

【问题讨论】:

    标签: python odoo division depends


    【解决方案1】:

    这取决于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    
    

    【讨论】:

    • 谢谢,完美运行!但是在字段默认值上添加为 1,因此不会出现除法错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-24
    • 2018-07-09
    • 2015-09-01
    • 1970-01-01
    • 2020-06-18
    • 2011-01-27
    • 1970-01-01
    相关资源
    最近更新 更多