【发布时间】:2020-12-16 18:18:48
【问题描述】:
我正在使用折扣值更新销售订单行,并且有些产品有一个选项没有折扣,这意味着在分配行上的折扣值时忽略它
方法如下
@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 odoo onchange odoo-12