微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在当前未保存的订单行上使用odoo onchange方法?

如何解决如何在当前未保存的订单行上使用odoo onchange方法?

我正在使用折扣值更新销售订单行,并且有些产品没有折扣选项,这意味着在分发折扣值时忽略该行

这是方法

@api.onchange('discount_type','discount_rate','order_line','discount_durar')
def set_lines_discount(self):
    total = discount = 0.0
    for line in self.order_line:
        if self.discount_type == 'percentage':
            if line.no_discount_field:
                line.discount_durar = 0
            else:
                line.discount_durar = self.discount_rate
        else:
            if line.no_discount_field == True:
                line.discount_durar = 0
            else:
                total += (line.product_uom_qty * line.price_unit)
                if self.discount_rate != 0:
                    discount = (self.discount_rate / total) * 100
                else:
                    discount = self.discount_rate
                for line in self.order_line.search([('no_discount_field','=',False)]):
                    line.discount_durar = discount

它在所有条件下都能正常工作,除了我使用的最后一个条件,它需要保存顺序才能计算出来并遍历所有行。

在保存订单之前,如何在条件中循环?

解决方法

您可以使用带条件的python单行列表理解。在您的情况下,您可以拥有类似的东西。

[line for line in self.order_line if condition]
,

我使用过滤器更改了sale.order.line搜索对象

for line in self.order_line.filtered(lambda l: not l.no_discount_field):

然后效果很好

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。