gpt4 book ai didi

python - Python 3 continue 循环语句在 Odoo 13 的计算方法中是否存在问题?

转载 作者:行者123 更新时间:2023-12-02 07:13:45 25 4
gpt4 key购买 nike

我正在将模块迁移到版本 13.0,该版本在计算方法内的循环中使用 continue,并且一个错误让我发疯了一段时间。

我将代码简化到最少,直到出现这种废话:

@api.depends('move_lines', 'move_lines.price_subtotal')
def _compute_subtotal(self):
for picking in self:
if picking.picking_type_id.code not in ['incoming', 'outgoing']:
continue
picking.update({
'amount_untaxed': 3.0,
})

但我仍然收到错误,顺便说一下,这是这样的(并且仅在创建新选择时显示):

stock.picking(<NewId 0x7f5404ba5eb8>,).amount_untaxed

所以我意识到问题出在 continue 语句上,如果我删除它,它就会起作用。我尝试在标准 Odoo 模块的其他计算方法的几个循环中使用 continue ,得到相同的结果。

到目前为止,如果您没有为计算方法中的字段赋值,它会自动采用 False,因此 继续 不是问题。

有人在继续时也遇到过这个问题吗?

最佳答案

需要为每个记录集设置值。如果我们使用 continue 并且不为该特定记录集设置值,将会出现您提到的问题。

尝试使用以下代码:

@api.depends('move_lines', 'move_lines.price_subtotal')
def _compute_subtotal(self):
for picking in self:
amount_untaxed = 0.0
if picking.picking_type_id.code == 'internal':
amount_untaxed = 3.0
picking.update({
'amount_untaxed': amount_untaxed,
})

如果我们编写如下代码,Continue 就会起作用:

@api.depends('move_lines', 'move_lines.price_subtotal')
def _compute_subtotal(self):
for picking in self:
picking.update({
'amount_untaxed': 0.0,
})
if picking.picking_type_id.code not in ['incoming', 'outgoing']:
continue
picking.update({
'amount_untaxed': 3.0,
})

关于python - Python 3 continue 循环语句在 Odoo 13 的计算方法中是否存在问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60284789/

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