changeset 93db8103bcc4 in modules/product_kit:6.0
details: 
https://hg.tryton.org/modules/product_kit?cmd=changeset&node=93db8103bcc4
description:
        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
        (grafted from f4a92834bdb5a213cdacf6f53b28beea6612fc35)
diffstat:

 stock.py                                |  5 +++--
 tests/scenario_product_kit_purchase.rst |  7 +++++++
 tests/scenario_product_kit_sale.rst     |  7 +++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diffs (52 lines):

diff -r 645d2334fc0c -r 93db8103bcc4 stock.py
--- a/stock.py  Thu Sep 16 23:48:41 2021 +0200
+++ b/stock.py  Sat Oct 02 15:29:44 2021 +0200
@@ -22,11 +22,12 @@
                 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 -r 645d2334fc0c -r 93db8103bcc4 tests/scenario_product_kit_purchase.rst
--- a/tests/scenario_product_kit_purchase.rst   Thu Sep 16 23:48:41 2021 +0200
+++ b/tests/scenario_product_kit_purchase.rst   Sat Oct 02 15:29:44 2021 +0200
@@ -248,6 +248,13 @@
     >>> 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 -r 645d2334fc0c -r 93db8103bcc4 tests/scenario_product_kit_sale.rst
--- a/tests/scenario_product_kit_sale.rst       Thu Sep 16 23:48:41 2021 +0200
+++ b/tests/scenario_product_kit_sale.rst       Sat Oct 02 15:29:44 2021 +0200
@@ -231,6 +231,13 @@
     >>> 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

Reply via email to