diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 77d85dda035..81fe7ef0045 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1179,7 +1179,9 @@ class PurchaseOrderLine(models.Model): if not self.product_id: return - self.product_uom = self.product_id.uom_po_id or self.product_id.uom_id + # TODO: Remove when onchanges are replaced with computes + if not (self.env.context.get('origin_po_id') and self.product_uom and self.product_id.uom_id.category_id == self.product_uom_category_id): + self.product_uom = self.product_id.uom_po_id or self.product_id.uom_id product_lang = self.product_id.with_context( lang=get_lang(self.env, self.partner_id.lang).code, partner_id=self.partner_id.id, diff --git a/addons/purchase_requisition/tests/test_purchase_requisition.py b/addons/purchase_requisition/tests/test_purchase_requisition.py index 4555f36d55d..6c8f8ff76a3 100644 --- a/addons/purchase_requisition/tests/test_purchase_requisition.py +++ b/addons/purchase_requisition/tests/test_purchase_requisition.py @@ -285,6 +285,32 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon): po_1.order_line.price_unit, 16, "Line's unit price from the original PO shouldn't be changed") + def test_10_alternative_po_line_price_unit_different_uom(self): + """ Check that the uom is copied in the alternative PO, and the "unit_price" + is calculated according to this uom and not that of the product """ + # Creates a first Purchase Order. + po_form = Form(self.env['purchase.order']) + self.product_09.standard_price = 10 + po_form.partner_id = self.res_partner_1 + with po_form.order_line.new() as line: + line.product_id = self.product_09 + line.product_qty = 1 + line.product_uom = self.env.ref('uom.product_uom_dozen') + po_1 = po_form.save() + self.assertEqual(po_1.order_line[0].price_unit, 120) + + # Creates an alternative PO. + action = po_1.action_create_alternative() + alt_po_wizard_form = Form(self.env['purchase.requisition.create.alternative'].with_context(**action['context'])) + alt_po_wizard_form.partner_id = self.res_partner_1 + alt_po_wizard_form.copy_products = True + alt_po_wizard = alt_po_wizard_form.save() + alt_po_wizard.action_create_alternative() + + po_2 = po_1.alternative_po_ids - po_1 + self.assertEqual(po_2.order_line[0].product_uom, po_1.order_line[0].product_uom) + self.assertEqual(po_2.order_line[0].price_unit, 120) + def test_11_alternative_po_from_po_with_requisition_id(self): """Create a purchase order from a blanket order, then check that the alternative purchase order can be created and that the requisition_id is not set on it.