首页 > 解决方案 > Odoo,如何在自定义模块中从供应商信息中获取供应商价格值?

问题描述

我是 odoo 13 用户(不是开发人员)。在采购订单中添加产品行的自定义模块中,我需要添加:product_id、name、price_unit、tax_id。product_id、name、tax_id 值在 product.product 中可用,我可以使用以下代码获取其值:

'product_id': product.id,
'name': product.name,
'taxes_id': product.supplier_taxes_id,

但 'price_unit' 值在 product.supplierinfo (它是供应商价格)中,如果我使用代码:

'price_unit':  supplierinfo.price

我有错误:NameError: name 'supplierinfo' is not defined

我的错误是什么?如何从 product.supplierinfo 获取供应商价格值并将其分配给“price_unit”???

我不是开发人员,我不知道如何创建代码,请提供任何对代码表示赞赏的建议。谢谢下面的完整代码:

    def _add_product(self, product, qty, price):
        corresponding_line = self.order_line.filtered(lambda r: r.product_id.id == product.id)
        if corresponding_line:
            corresponding_line[0].product_qty += float(qty)
            corresponding_line[0].price_unit = float(price) or supplierinfo.price
        else:
            self.order_line += self.order_line.new({
                'product_id': product.id,
                'product_qty': qty,
                'date_planned': fields.Datetime.to_string(datetime.datetime.now() - dateutil.relativedelta.relativedelta(months=1)),
                'name': product.name,
                'product_uom': product.uom_id.id,
                'price_unit': float(price) or supplierinfo.price,       
                'taxes_id': product.supplier_taxes_id,
            })
        return True

标签: pythonodoo

解决方案


试试这个代码,

    def _add_product(self, product, qty, price):
        corresponding_line = self.order_line.filtered(lambda r: r.product_id.id == product.id)
        # My Cust Start
        supplierinfo = product.mapped('seller_ids')[:1]
        # My Cust End
        if corresponding_line:
            corresponding_line[0].product_qty += float(qty)
            corresponding_line[0].price_unit = float(price) or supplierinfo.price
        else:
            self.order_line += self.order_line.new({
                'product_id': product.id,
                'product_qty': qty,
                'date_planned': fields.Datetime.to_string(datetime.datetime.now() - dateutil.relativedelta.relativedelta(months=1)),
                'name': product.name,
                'product_uom': product.uom_id.id,
                'price_unit': float(price) or supplierinfo.price,       
                'taxes_id': product.supplier_taxes_id,
            })
        return True

谢谢


推荐阅读