如果某个特定字段的输出值为负数,那么在Odoo中查看XML文件时,如何将其设置为0



我正在尝试计算ORM中两个字段之间的差值。如果结果值为负数,则当我使用XML显示此字段值时,结果值将为0。

excess_amount = fields.Float(string="Excess amount", compute='difference_excess_amount')

def difference_excess_amount(self):
for rec in self:
rec.excess_amount = rec.actual_total - rec.expected_total
<field name="excess_amount"/>

请尝试以下代码

@api.depends('actual_total', 'expected_total')
def difference_excess_amount(self):
for rec in self:
excess_amount = rec.actual_total - rec.expected_total
rec.excess_amount = 0 if excess_amount < 0 else excess_amount
@api.depends('actual_total', 'expected_total')
def difference_excess_amount(self):
for rec in self:
rec.excess_amount = rec.actual_total - rec.expected_total
if rec.excess_amount < 0:
rec.excess_amount = 0

这应该行得通。

相关内容

  • 没有找到相关文章

最新更新