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

ValueError:解包的值太多odoo

如何解决ValueError:解包的值太多odoo

当产品名称为 ups standard 或 saver 时,我想从订单行中提取估计成本, 我总是收到此错误:ValueError:要解压缩的值太多(预期为 1) ValueError:预期的单例:sale.order.line(118,119,120,121)

我该怎么办?任何帮助请

@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 

解决方法

你需要改变

self.estim_cost=estim_cost

order_line.estim_cost=estim_cost
,

你在这一行错了:

self.estim_cost=estim_cost

您应该使用 order_line 而不是 self。 这里 self 是 multiton sale.order.line(118,119,120,121) 在这种情况下你不能使用做作运算符。
PS:如果你想在记录集中写一个值,使用方法.write()

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