Hi, I'm a odoo 13 user (not developer).
In a custom module which add products lines in Purchase Order, I need to add: product_id, name, price_unit , taxes_id.
product_id, name, taxes_id values are available in product.product and I can get its value with this code:
'product_id': product.id,
'name': product.name,
'taxes_id': product.supplier_taxes_id,
but 'price_unit' value is in product.supplierinfo (it's supplier price) and if I use code:
'price_unit': supplierinfo.price
I have error: NameError: name 'supplierinfo' is not defined
What's my mistake? How I can get Supplier Price value from product.supplierinfo and assign it to 'price_unit'???
I'm not developer and I don't know how create code, please any suggestion it's appreciated with code.
Thanks
Below complete code:
def _add_product(self, product, qty, price):
"""Add line or update qty and price based on barcode."""
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