summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchraf (abz) <abz@odoo.com>2021-04-13 06:46:58 +0000
committerAchraf (abz) <abz@odoo.com>2021-04-13 13:11:47 +0000
commitd531e8a5e4d84fe6daa9110d076b0fc601a0b4d9 (patch)
treebdc09451fcb4a73fdc6a719b77c4189bb4f40eb0
parente5880130c1534217c5bae905af8e5a040f40a819 (diff)
[FIX] purchase: Update correctly the price according to UoM
What are the steps to reproduce your issue ? 1. Create Product with Purchase Vendor(s) set 2. Create Units of Measure that are bigger than (10kg/50kg in tests) What is currently happening ? If you put a vendor that is listed in product form, when changing purchase unit from kg to 10/50kg price is updated If you put a vendor not listed, it gives cost price which is correct, but does not update price according to unit of measure. What are you expecting to happen ? Update correctly the unit of measure when the vendor is not listed opw-2494769 closes odoo/odoo#69148 Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
-rw-r--r--addons/purchase/models/purchase.py4
-rw-r--r--addons/purchase_stock/tests/test_onchange_product.py36
2 files changed, 34 insertions, 6 deletions
diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py
index e28ff9e4243..56793330d20 100644
--- a/addons/purchase/models/purchase.py
+++ b/addons/purchase/models/purchase.py
@@ -1058,6 +1058,10 @@ class PurchaseOrderLine(models.Model):
self.order_id.company_id,
self.date_order or fields.Date.today(),
)
+
+ if self.product_uom:
+ price_unit = self.product_id.uom_id._compute_price(price_unit, self.product_uom)
+
self.price_unit = price_unit
return
diff --git a/addons/purchase_stock/tests/test_onchange_product.py b/addons/purchase_stock/tests/test_onchange_product.py
index dc75bf8ce5c..b029839e035 100644
--- a/addons/purchase_stock/tests/test_onchange_product.py
+++ b/addons/purchase_stock/tests/test_onchange_product.py
@@ -4,7 +4,7 @@
from datetime import datetime
from odoo import fields
-from odoo.tests.common import TransactionCase
+from odoo.tests.common import TransactionCase, Form
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class TestOnchangeProductId(TransactionCase):
@@ -82,16 +82,40 @@ class TestOnchangeProductId(TransactionCase):
po_line.write({'product_qty': 3, 'product_uom': self.ref("uom.product_uom_dozen")})
po_line._onchange_quantity()
self.assertEqual(1200, po_line.price_unit, "Unit price should be 1200 for one Dozen")
-
- product_ipad = self.env['product.product'].create({'name': 'Conference Chair'})
+ ipad_uom = self.env['uom.category'].create({'name': 'Ipad Unit'})
+ ipad_lot = self.env['uom.uom'].create({
+ 'name': 'Ipad',
+ 'category_id': ipad_uom.id,
+ 'uom_type': 'reference',
+ 'rounding': 0.001
+ })
+ ipad_lot_10 = self.env['uom.uom'].create({
+ 'name': '10 Ipad',
+ 'category_id': ipad_uom.id,
+ 'uom_type': 'bigger',
+ 'rounding': 0.001,
+ "factor_inv": 10
+ })
+ product_ipad = self.env['product.product'].create({
+ 'name': 'Conference Chair',
+ 'standard_price': 100,
+ 'uom_id': ipad_lot.id,
+ 'uom_po_id': ipad_lot.id,
+ })
po_line2 = self.po_line_model.create({
'name': product_ipad.name,
'product_id': product_ipad.id,
'order_id': po.id,
'product_qty': 5,
- 'product_uom': uom_id.id,
- 'price_unit': 100.0,
+ 'product_uom': ipad_uom.id,
'date_planned': fields.Date().today()
})
+
po_line2.onchange_product_id()
- self.assertEqual(0, po_line2.price_unit, "No vendor supplies this product, hence unit price should be set to 0")
+ self.assertEqual(100, po_line2.price_unit, "No vendor supplies this product, hence unit price should be set to 100")
+
+ po_form = Form(po)
+ with po_form.order_line.edit(1) as order_line:
+ order_line.product_uom = ipad_lot_10
+ po_form.save()
+ self.assertEqual(1000, po_line2.price_unit, "The product_uom is multiplied by 10, hence unit price should be set to 1000")