Skip to content

Commit

Permalink
[FIX] purchase: vendor price not converted to default UoM
Browse files Browse the repository at this point in the history
-Define "g" as the default UoM for a product.
-Make a purchase order with that product.
-Select the "kg" UoM in the order line and a price of 50.
-Check the Purchase tab of the product.

Before this commit:

the UoM of the price created is the default UoM for the product, "g".
This is because it's a related field.
However, the price wasn't converted to the default UoM, it's still 50.

After this commit:

the price is converted to the default UoM, it's 0.05 per "g".

closes #38522

Opw: 2076722
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information
fw-bot authored and Florimond committed Oct 14, 2019
1 parent 44226ec commit 341b568
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions addons/purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,19 @@ def _add_supplier_to_product(self):
# Do not add a contact as a supplier
partner = self.partner_id if not self.partner_id.parent_id else self.partner_id.parent_id
if line.product_id and partner not in line.product_id.seller_ids.mapped('name') and len(line.product_id.seller_ids) <= 10:
# Convert the price in the right currency.
currency = partner.property_purchase_currency_id or self.env.company.currency_id
price = self.currency_id._convert(line.price_unit, currency, line.company_id, line.date_order or fields.Date.today(), round=False)
# Compute the price for the template's UoM, because the supplier's UoM is related to that UoM.
if line.product_id.product_tmpl_id.uom_po_id != line.product_uom:
default_uom = line.product_id.product_tmpl_id.uom_po_id
price = line.product_uom._compute_price(price, default_uom)

supplierinfo = {
'name': partner.id,
'sequence': max(line.product_id.seller_ids.mapped('sequence')) + 1 if line.product_id.seller_ids else 1,
'product_uom': line.product_uom.id,
'min_qty': 0.0,
'price': self.currency_id._convert(line.price_unit, currency, line.company_id, line.date_order or fields.Date.today(), round=False),
'price': price,
'currency_id': currency.id,
'delay': 0,
}
Expand Down

0 comments on commit 341b568

Please sign in to comment.