From 11bdfa7b0cdd55fe680d1f7c09a1456bc68e1892 Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Fri, 19 Jul 2024 18:38:52 +0200 Subject: [PATCH] [FIX] get only valid procurement group stock_orderpoint_origin --- .../models/procurement_group.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/stock_orderpoint_origin/models/procurement_group.py b/stock_orderpoint_origin/models/procurement_group.py index e15bd0e504a8..6bb72452a95c 100644 --- a/stock_orderpoint_origin/models/procurement_group.py +++ b/stock_orderpoint_origin/models/procurement_group.py @@ -29,14 +29,23 @@ def run(self, procurements, raise_user_error=True): # stock.picking object doesn't have field procurement_group_id, # so we check if the source document is a picking to use the # correct field (group_id) - source_groups = [ - x.procurement_group_id if x._name != "stock.picking" else x.group_id - for x in source_docs - ] + source_groups = [] + for source_doc in source_docs: + if ( + source_doc.procurement_group_id + if source_doc._name != "stock.picking" + else source_doc.group_id + ): + source_groups.append( + source_doc.procurement_group_id + if source_doc._name != "stock.picking" + else source_doc.group_id + ) source_names = ", ".join([x.name for x in source_docs]) new_origin = "%s (from %s)" % (source_names, procurement.origin) new_procurement = procurement._replace(origin=new_origin) - new_procurement.values["source_group_ids"] = source_groups + if source_groups: + new_procurement.values["source_group_ids"] = source_groups new_procurements.append(new_procurement) else: new_procurements.append(procurement)