此方法返回相关qty_available
的产品数量(product_id
),它工作正常,问题是保存或确认操作时我得到默认值qty_available
def onchange_product_id(self, cr, uid, ids, product_id=False, product_uom_qty=0.0, product_uom=False, price_unit=0.0, qty_available=0.0, virtual_available=0.0, name='', analytic_account_id=False, context=None):
result = {}
product_obj = self.pool.get('product.product')
if not product_id:
return {'value': {'product_uom_qty': 1.0, 'product_uom': False, 'price_unit': 0.0, 'qty_available': 0.0, 'virtual_available': 0.0, 'name': '', 'delay': 0.0}}
product = product_obj.browse(cr, uid, product_id, context=context)
result['name'] = product_obj.name_get(cr, uid, [product.id])[0][1]
result['product_uom'] = product.uom_id.id
result['qty_available'] = product.qty_available
return {'value': result}
答案 0 :(得分:0)
尝试以下在新API Odoo V8中转换的代码:
//remove this file
boolean result = new File(myDBpath).delete();
答案 1 :(得分:0)
这是解决方案。
def onchange_product_id(self, cr, uid, ids, product_id=False, product_uom_qty=0.0, product_uom=False, price_unit=0.0, qty_available=0.0, virtual_available=0.0, name='', analytic_account_id=False, context=None):
result = {}
product_obj = self.pool.get('product.product')
if not product_id:
return {'value': {'product_uom_qty': 1.0, 'product_uom': False, 'price_unit': 0.0, 'qty_available': 0.0, 'virtual_available': 0.0, 'name': '', 'delay': 0.0}}
product = product_obj.browse(cr, uid, product_id, context=context)
res['value'].update({'name': product_obj.name_get(cr, uid, [product.id])[0][1], 'product_uom': product.uom_id.id, 'qty_available': product.qty_available})
return res