From b4da05c6cf8cc69f9c73ddc3b78bfbe1793cf149 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 14 Aug 2024 13:30:26 +0200 Subject: [PATCH] [IMP] mrp_multi_level: better logs during calculation * Explicitly log which area and LLC is being computed. * Correct LLC being logged. --- mrp_multi_level/wizards/mrp_multi_level.py | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/mrp_multi_level/wizards/mrp_multi_level.py b/mrp_multi_level/wizards/mrp_multi_level.py index 244dac14b4..6d4e619e24 100644 --- a/mrp_multi_level/wizards/mrp_multi_level.py +++ b/mrp_multi_level/wizards/mrp_multi_level.py @@ -723,30 +723,39 @@ def _exclude_move(self, move): """Improve extensibility being able to exclude special moves.""" return False - @api.model - def _mrp_calculation(self, mrp_lowest_llc, mrp_areas): - logger.info("Start MRP calculation") + def _get_mrp_initialization_groups_of_params(self, mrp_lowest_llc, mrp_areas): product_mrp_area_obj = self.env["product.mrp.area"] - counter = 0 - if not mrp_areas: - mrp_areas = self.env["mrp.area"].search([]) + groups = {} for mrp_area in mrp_areas: llc = 0 while mrp_lowest_llc > llc: - product_mrp_areas = product_mrp_area_obj.search( + groups[mrp_area, llc] = product_mrp_area_obj.search( [("product_id.llc", "=", llc), ("mrp_area_id", "=", mrp_area.id)] ) llc += 1 + return groups - for product_mrp_area in product_mrp_areas: - if product_mrp_area.mrp_nbr_days == 0: - self._init_mrp_move_non_grouped_demand(product_mrp_area) - else: - self._init_mrp_move_grouped_demand(product_mrp_area) - counter += 1 + @api.model + def _mrp_calculation(self, mrp_lowest_llc, mrp_areas): + logger.info("Start MRP calculation") + if not mrp_areas: + mrp_areas = self.env["mrp.area"].search([]) + keyed_groups = self._get_mrp_initialization_groups_of_params( + mrp_lowest_llc, mrp_areas + ) + for (mrp_area, llc), product_mrp_areas in keyed_groups.items(): + counter = 0 + for product_mrp_area in product_mrp_areas: + if product_mrp_area.mrp_nbr_days == 0: + self._init_mrp_move_non_grouped_demand(product_mrp_area) + else: + self._init_mrp_move_grouped_demand(product_mrp_area) + counter += 1 - log_msg = "MRP Calculation LLC {} Finished - Nbr. products: {}".format( - llc - 1, counter + log_msg = ( + "MRP Calculation LLC {} at {} Finished - Nbr. products: {}".format( + llc, mrp_area.name, counter + ) ) logger.info(log_msg)