希望获得基于位置的产品可用数量(odoo 12)

2024-05-06 02:15:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要获得每个仓库的产品可用数量,并在产品视图列表中将其作为列进行预览

有人能告诉我下面的代码有什么问题吗

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>

Tags: nameselfviewtreefield产品checktemplate