From 502359eaa37c069849fd237efedb4b9dfba43327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 2 Oct 2021 15:29:44 +0200 Subject: [PATCH] Convert invoiced quantity into the order line unit And only after applying the price ratio, we can convert from the price from the component unit to the move unit. issue10800 review375611002 --- stock.py | 5 +++-- tests/scenario_product_kit_purchase.rst | 7 +++++++ tests/scenario_product_kit_sale.rst | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/stock.py b/stock.py index a309ef46a4..db7948e235 100644 --- a/stock.py +++ b/stock.py @@ -22,11 +22,12 @@ class Move(metaclass=PoolMeta): with Transaction().set_context(date=self.effective_date): amount += Currency.compute( line.invoice.currency, line.amount, self.currency) - quantity = UoM.compute_qty( - line.unit, line.quantity, self.uom) + quantity += UoM.compute_qty( + line.unit, line.quantity, self.origin.line.unit) amount *= self.origin.price_ratio if quantity: unit_price = round_price(amount / Decimal(str(quantity))) + unit_price = UoM.compute_price(self.origin.unit, unit_price, self.uom) return unit_price diff --git a/tests/scenario_product_kit_purchase.rst b/tests/scenario_product_kit_purchase.rst index 1709c4f403..27c4db88f8 100644 --- a/tests/scenario_product_kit_purchase.rst +++ b/tests/scenario_product_kit_purchase.rst @@ -248,6 +248,13 @@ Post invoice:: >>> invoice.state 'posted' +Check unit price of moves:: + + >>> shipment.reload() + >>> invoice.reload() + >>> sorted([m.unit_price for m in shipment.incoming_moves]) + [Decimal('5.0000'), Decimal('5.0000'), Decimal('7.0909'), Decimal('18.9091')] + Check backorder moves:: >>> len(purchase.moves) diff --git a/tests/scenario_product_kit_sale.rst b/tests/scenario_product_kit_sale.rst index 04f1d3efe7..6477d41153 100644 --- a/tests/scenario_product_kit_sale.rst +++ b/tests/scenario_product_kit_sale.rst @@ -231,6 +231,13 @@ Post invoice:: >>> invoice.state 'posted' +Check unit price of moves:: + + >>> shipment.reload() + >>> invoice.reload() + >>> sorted([m.unit_price for m in shipment.outgoing_moves]) + [Decimal('10.0000'), Decimal('10.0000'), Decimal('15.0000'), Decimal('25.0000')] + Check backorder:: >>> _, backorder = sale.shipments