From fecfe235f5e72aec68e69e4dc82415f59a560006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 13 Jan 2020 23:54:20 +0100 Subject: [PATCH] Count as quantity to invoice only moves that leave the source issue8951 review266621003 --- purchase.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/purchase.py b/purchase.py index 536df16c84..e0d7757c28 100644 --- a/purchase.py +++ b/purchase.py @@ -1424,9 +1424,18 @@ class PurchaseLine(sequence_ordered(), ModelSQL, ModelView): elif self.purchase.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 from_location + # as it is what matters for purchase + src_type = self.from_location.type + if (move.from_location.type == src_type + and move.to_location.type != src_type): + quantity += qty + elif (move.to_location.type == src_type + and move.from_location.type != src_type): + quantity -= qty if self.quantity < 0: quantity *= -1 return quantity