From f52bcddcccba619253352097ede7a889edb8e8e0 Mon Sep 17 00:00:00 2001
From: "Andrea Grazioso (agr-odoo)" <agr@odoo.com>
Date: Thu, 7 Nov 2019 08:37:04 +0000
Subject: [PATCH] [FIX] stock_move: show source document

Install stock and sale. Create a sale with 2+ products, save and
confirm.
Look for the created picking.

There will be no source doument, because of
cb618e9a99ea3b86fdeed0295168a1e9fd7cddc3
the behavior has changed when there are multiple source
document, possibly to avoid displaying the wrong source if they
differ.

Adding the possibility to display multiple source documents, eventually
truncating the list

opw-2117886

closes odoo/odoo#40098

X-original-commit: baad02d01b86a8d036524b789f046a54a878a729
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
---
 addons/stock/models/stock_move.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py
index 29be782a9fb5..616630deb47f 100644
--- a/addons/stock/models/stock_move.py
+++ b/addons/stock/models/stock_move.py
@@ -907,8 +907,16 @@ class StockMove(models.Model):
         """ return create values for new picking that will be linked with group
         of moves in self.
         """
-        origins = set(self.filtered(lambda m: m.origin).mapped('origin'))
-        origin = len(origins) == 1 and origins.pop() or False
+        origins = self.filtered(lambda m: m.origin).mapped('origin')
+        origins = list(dict.fromkeys(origins)) # create a list of unique items
+        # Will display source document if any, when multiple different origins
+        # are found display a maximum of 5
+        if len(origins) == 0:
+            origin = False
+        else:
+            origin = ','.join(origins[:5])
+            if len(origins) > 5:
+                origin += "..."
         partners = self.mapped('partner_id')
         partner = len(partners) == 1 and partners.id or False
         return {
-- 
GitLab