python - python TypeError:'crm.lead.product'对象不能解释为整数,Odoo 14
问题描述
'lead_product_ids' 由产品列表组成,我试图将每个产品的 qty*price 单位相乘以获得总数,然后将所有总数相加。
错误:TypeError:“crm.lead.product”对象不能解释为整数
代码
@api.depends('lead_product_ids.qty', 'lead_product_ids.price_unit', 'lead_product_ids')
def _compute_total_price(self):
for rec in self:
for i in rec.lead_product_ids:
for all in range(i):
total = (all.qty * all.price_unit)
rec.total_qty_price_unit = sum(total) or 0
解决方案
看起来像
for i in rec.lead_product_ids:
正在为 中的每个产品分配i
一个产品lead_product_ids
。
所以,当你这样做
for all in range(i):
它将尝试执行range()
但i
需要range()
一个整数输入——不是产品对象,因此会出现错误
TypeError:“crm.lead.product”对象不能解释为整数
为了解决这个问题,你应该i
改用。
@api.depends('lead_product_ids.qty', 'lead_product_ids.price_unit', 'lead_product_ids')
def _compute_total_price(self):
for rec in self:
for i in rec.lead_product_ids:
total = (i.qty * i.price_unit)
rec.total_qty_price_unit += total
推荐阅读
- python - NewRandomAccessFile 未能创建/打开;注意_OCR
- azure-web-app-service - Web App 的 Azure WAF 更改 HostName
- r - R Web Scraping:网页不包含表格时的错误处理
- amazon-web-services - 使用转发代理而不在客户端配置代理服务器,而是使用路由表
- python - 提取 PDF 的特定页面并使用 Python 保存
- python - 为什么这个带有 Matplotlib 的 Python 脚本这么慢?
- intellij-idea - IntelliJ 上的 JUnit 不工作
- html - IE 11 和 Firefox 中奇怪的悬停行为
- php - 在laravel中将变量传递给路由时找不到404
- java - RecycleView Multi ViewHolder中如何使用数组显示数据?