Help

0

How get supplier Price value from supplierinfo, in custom module???

Avatar
Lauriola Daniele

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

Avatar
Discard
2 Answers
0
Avatar
Lauriola Daniele
Best Answer

Hi Lee Marocs, I've try it but I have error:

AttributeError: 'purchase.order' object has no attribute 'order_id'
How can I do?

Thanks


Avatar
Discard
0
Avatar
Lee Marocs
Best Answer

Hi,

  Just try this 

       

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)
seller_min_qty = product.seller_ids \
.filtered(
lambda r: r.name == self.order_id.partner_id and (not r.product_id or r.product_id == product)) \
.sorted(key=lambda r: r.min_qty)
if seller_min_qty:
price = seller_min_qty[0].price
if corresponding_line:
corresponding_line[0].product_qty += float(qty)
corresponding_line[0].price_unit = price
else:
self.order_line += self.order_line.new({
'product_id': product.id,
'product_qty': qty,
'price_unit': price,
'taxes_id': product.supplier_taxes_id,
})
return True

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Avatar
Discard