我需要获取每个仓库的可用产品数量并将其作为产品视图列表中的一列进行预览。
任何人都可以指导我以下代码有什么问题吗?
class ProductTemplate(models.Model):
_inherit = 'product.template'
warehouse1_quantity = fields.Float('RYD Qty', compute='product_qty_ warehouse1_check')
@api.multi
def product_qty_ warehouse1_check(self):
for record in self:
product = self.env['product.product'].browse(PRODUCT_ID)
warehouse1_quantity = product.with_context({'warehouse' : 'RYD Inventory'}).qty_available
record.warehouse1_quantity
<record id="product_template_view_tree_inherit" model="ir.ui.view">
<field name="name">product.template.view.tree.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<xpath expr="//field[last()]" position="after">
<field name="warehouse1_quantity"/>
</xpath>
</field>
</record>
我认为您尚未将值分配给对象变量。
应该是:
record.warehouse1_quantity = product.with_context({'warehouse' : 'RYD Inventory'}).qty_available