changeset 0257ec68a234 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=0257ec68a234
description:
        Count as quantity to invoice only moves that reach the destination

        issue8951
        review264961002
diffstat:

 sale.py |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (25 lines):

diff -r 79d2c40d90a4 -r 0257ec68a234 sale.py
--- a/sale.py   Mon Jan 13 23:48:22 2020 +0100
+++ b/sale.py   Mon Jan 13 23:54:01 2020 +0100
@@ -1371,9 +1371,18 @@
         elif self.sale.invoice_method == 'shipment':
             quantity = 0.0
             for move in self.moves:
-                if move.state == 'done':
-                    quantity += Uom.compute_qty(move.uom, move.quantity,
-                        self.unit)
+                if move.state != 'done':
+                    continue
+                qty = Uom.compute_qty(move.uom, move.quantity, self.unit)
+                # Test only against to_location
+                # as it is what matters for sale
+                dest_type = self.to_location.type
+                if (move.to_location.type == dest_type
+                        and move.from_location.type != dest_type):
+                    quantity += qty
+                elif (move.from_location.type == dest_type
+                        and move.to_location.type != dest_type):
+                    quantity -= qty
             if self.quantity < 0:
                 quantity *= -1
             return quantity

Reply via email to