ValueError:要解压缩的值太多(odoo)

2024-04-25 06:33:44 发布

您现在位置:Python中文网/ 问答频道 /正文

当产品名称为ups standard或saver时,我想从订单行提取估计成本, 我总是遇到以下错误:ValueError:要解压缩的值太多(预期为1) ValueError:预期单例:销售.订单.行(118119120121)

我该怎么办?需要帮忙吗

@api.depends('product_id.name')
def _compute_estimated_cost(self):
        estim_cost = 0
        #
        for order_line in self:
            if order_line.product_id.name in ['UPS Standard' ,'UPS Saver']:
                for word in order_line.product_id.name.split():
                    try: 
                        estim_cost += round(float(word),2)
                        self.estim_cost=estim_cost
                       
                        break
                    except:
                        continue
            else:
                pass 

Tags: namein订单selfidforlineorder
2条回答

您在这一行有错误:

self.estim_cost=estim_cost

您应该使用订单行而不是self。 这里self是multitonsale.order.line(118、119、120、121),在这种情况下不能使用矫揉造作操作符
PS:如果要在记录集中写入值,请使用方法.write()

你需要改变

self.estim_cost=estim_cost

order_line.estim_cost=estim_cost

相关问题 更多 >