From ee8a7559d29fafb526bdd610f807b6f44dee167a Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Thu, 22 Aug 2024 10:28:58 +0200 Subject: [PATCH] mrp_sale_info: add measure to avoide infinite recursion error --- mrp_sale_info/models/stock_move.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mrp_sale_info/models/stock_move.py b/mrp_sale_info/models/stock_move.py index 62adde559..2ff41b648 100644 --- a/mrp_sale_info/models/stock_move.py +++ b/mrp_sale_info/models/stock_move.py @@ -6,11 +6,20 @@ from odoo import models class StockMove(models.Model): _inherit = "stock.move" - def _get_orig_created_production_ids(self): + def _get_orig_created_production_ids(self, already_scanned_ids=None): self.ensure_one() if self.created_production_id: return self.created_production_id + if not already_scanned_ids: + # 'already_scanned_ids' is used to avoid infinite loop errors, + # we only call this method recursively for moves that haven't been handled yet. + already_scanned_ids = [] mrp_production_ids = set() for move in self.move_orig_ids: - mrp_production_ids.update(move._get_orig_created_production_ids().ids) + if move.id in already_scanned_ids: + return self.env["mrp.production"] + already_scanned_ids.append(move.id) + mrp_production_ids.update( + move._get_orig_created_production_ids(already_scanned_ids).ids + ) return self.env["mrp.production"].browse(mrp_production_ids)