不要返回任何值。
如Odoo网站所述
You should assign the computed value to the field
:
计算字段
可以使用compute参数计算字段(而不是直接从数据库读取)。它必须将计算值分配给字段。如果它使用其他字段的值,则应使用depends()指定这些字段
评估后
price_uom = wiz.pricelist_id.price_get(wiz.product_id.id, 1)
:
price_uom
将是一份口述(
{pricelist_id: price}
)因此,在尝试执行任何算术运算之前,您需要获取price\u uom。
@api.depends('pricelist_id', 'quantity', 'product_id')
def _compute_price(self):
# for regular barcodes
for wiz in self:
if wiz.pricelist_id and wiz.product_id:
# You need to get price from the dict using pricelist_id
price_uom = wiz.pricelist_id.price_get(wiz.product_id.id, 1)[wiz.pricelist_id.id]
wiz.price_uom = price_uom
wiz.price = price_uom * wiz.quantity
return wiz.price
您可以看到
price_get
如果您查看以下代码(我刚刚复制了所需的最小代码),就会计算返回值:
def price_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
return dict((key, price[0]) for key, price in self.price_rule_get(cr, uid, ids, prod_id, qty, partner=partner, context=context).items())
def price_rule_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
product = self.pool.get('product.product').browse(cr, uid, prod_id, context=context)
res_multi = self.price_rule_get_multi(cr, uid, ids, products_by_qty_by_partner=[(product, qty, partner)], context=context)
res = res_multi[prod_id]
return res
def price_rule_get_multi(self, cr, uid, ids, products_by_qty_by_partner, context=None):
"""multi products 'price_get'.
@param ids:
@param products_by_qty:
@param partner:
@param context: {
'date': Date of the pricelist (%Y-%m-%d),}
@return: a dict of dict with product_id as key and a dict 'price by pricelist' as value
"""
if not ids:
ids = self.pool.get('product.pricelist').search(cr, uid, [], context=context)
results = {}
for pricelist in self.browse(cr, uid, ids, context=context):
subres = self._price_rule_get_multi(cr, uid, pricelist, products_by_qty_by_partner, context=context)
for product_id, price in subres.items():
results.setdefault(product_id, {})
results[product_id][pricelist.id] = price
return results