python - 想要根据位置获取产品可用数量(odoo 12)
问题描述
我需要获取每个仓库的可用产品数量,并将其作为产品视图列表中的一列进行预览。
谁能指导我以下代码有什么问题?
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
推荐阅读
- python - 这个for循环可以减少到一行吗?
- javascript - 一次播放多个 HTML5 视频
- javascript - 如何解压缩这个编码的 javascript 代码?
- jquery - 如何为 CKeditor 4 插件添加灰色边框?
- python - 定义一个在第一次 __next__() 调用之前更新全局变量的生成器
- c - C 语言:如何评估信号处理程序的返回值?
- python-3.x - Python Typing:创建一个具有泛型类型的类函数,并通过该类访问该类型
- python - 如何使用 matplotlib imshow 为数组设置动画?
- regex - 匹配以大写字母开头的单词直到以大写字母开头的单词
- flutter - Flutter StatefulWidget 小部件和泛型