gpt4 book ai didi

python - 如何计算 odoo 13 销售订单行上的字段?

转载 作者:行者123 更新时间:2023-12-04 00:16:25 25 4
gpt4 key购买 nike

我正在尝试计算销售订单行上的折扣字段,该方法在 odoo 12 中运行良好,但在 odoo 13 中,每次尝试添加行时都会出现此错误

sale.order.line(<NewId 0x7f3dd0d624a8>,).discount_mount

这就是我所做的

class discount_cycle(models.Model):
_inherit = 'sale.order.line'

discount_mount = fields.Float(string="", required=False , compute='discount_calculation')


@api.depends('product_id','discount','price_subtotal')
def discount_calculation(self):
for rec in self:
if rec.discount:
if rec.product_uom_qty > 1:
rec.discount_mount = ((rec.price_unit * rec.product_uom_qty) * (rec.discount / 100))
else:
rec.discount_mount = (rec.price_unit * (rec.discount / 100))
pass

请注意,在 odoo V 12 中是 @api.one,那么我该如何解决这个问题以及在这种情况下 @api.one 的替代品是什么

最佳答案

在 odoo V13 中,您必须将值分配给计算字段而不是 pass 您需要添加 else 语句并分配默认值

     else:
self.discount_mount = 0.0

我知道这很清楚,如果我们没有折扣,那么该字段应该是 0.0,但 odoo 希望你这样做

关于python - 如何计算 odoo 13 销售订单行上的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63559639/

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