From 25ae2416b08c6b3b1805b1f5de7df283d3a8ef0c Mon Sep 17 00:00:00 2001
From: Denis Roussel <denis.roussel@acsone.eu>
Date: Sat, 13 Feb 2021 11:33:47 +0000
Subject: [PATCH] [FIX] stock: Don't take into account canceled moves to check
 for backorder

Do a transfer in two steps with several move lines (e.g.: Vendors => Input => Stock).

In the first picking, set quantity = 0 on a single line. Transfer it and say 'No backorder'.

In the second picking, set all quantities (you have two move lines confirmed and one canceled). Validate the
transfer. The backorder wizard is launched. It should not.

closes odoo/odoo#66122

Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
---
 addons/stock/models/stock_picking.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py
index b97238e90f45..b963e454fd1a 100644
--- a/addons/stock/models/stock_picking.py
+++ b/addons/stock/models/stock_picking.py
@@ -944,7 +944,9 @@ class Picking(models.Model):
         """
         quantity_todo = {}
         quantity_done = {}
-        for move in self.mapped('move_lines'):
+        # If a preceding move has been canceled and propagated state to its
+        # destination move, we don't take quantities into account
+        for move in self.mapped('move_lines').filtered(lambda m: m.state != "cancel"):
             quantity_todo.setdefault(move.product_id.id, 0)
             quantity_done.setdefault(move.product_id.id, 0)
             quantity_todo[move.product_id.id] += move.product_uom_qty
-- 
GitLab