From 978e08f3a385b6a921e27df016768a11a6e200db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 24 Sep 2023 23:06:03 +1000 Subject: [PATCH] stop cascade update_pricing if prices didnt change (#5606) (#5607) Co-authored-by: Oliver Lippert (cherry picked from commit 2f0dbf97768e7dbae495216969a3fe35b2cb2b8f) Co-authored-by: Oliver Lippert --- InvenTree/part/models.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index aa331ce386d..bf7ed43bb7b 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2346,6 +2346,8 @@ class PartPricing(common.models.MetaMixin): - Detailed pricing information is very context specific in any case """ + price_modified = False + @property def is_valid(self): """Return True if the cached pricing is valid""" @@ -2472,7 +2474,7 @@ def update_pricing(self, counter: int = 0, cascade: bool = True): pass # Update parent assemblies and templates - if cascade: + if cascade and self.price_modified: self.update_assemblies(counter) self.update_templates(counter) @@ -2572,6 +2574,9 @@ def update_bom_cost(self, save=True): any_max_elements = True + old_bom_cost_min = self.bom_cost_min + old_bom_cost_max = self.bom_cost_max + if any_min_elements: self.bom_cost_min = cumulative_min else: @@ -2582,6 +2587,9 @@ def update_bom_cost(self, save=True): else: self.bom_cost_max = None + if old_bom_cost_min != self.bom_cost_min or old_bom_cost_max != self.bom_cost_max: + self.price_modified = True + if save: self.save() @@ -2646,6 +2654,9 @@ def update_purchase_cost(self, save=True): if purchase_max is None or cost > purchase_max: purchase_max = cost + if self.purchase_cost_min != purchase_min or self.purchase_cost_max != purchase_max: + self.price_modified = True + self.purchase_cost_min = purchase_min self.purchase_cost_max = purchase_max @@ -2673,6 +2684,9 @@ def update_internal_cost(self, save=True): if max_int_cost is None or cost > max_int_cost: max_int_cost = cost + if self.internal_cost_min != min_int_cost or self.internal_cost_max != max_int_cost: + self.price_modified = True + self.internal_cost_min = min_int_cost self.internal_cost_max = max_int_cost @@ -2712,6 +2726,9 @@ def update_supplier_cost(self, save=True): if max_sup_cost is None or cost > max_sup_cost: max_sup_cost = cost + if self.supplier_price_min != min_sup_cost or self.supplier_price_max != max_sup_cost: + self.price_modified = True + self.supplier_price_min = min_sup_cost self.supplier_price_max = max_sup_cost @@ -2749,6 +2766,9 @@ def update_variant_cost(self, save=True): if variant_max is None or v_max > variant_max: variant_max = v_max + if self.variant_cost_min != variant_min or self.variant_cost_max != variant_max: + self.price_modified = True + self.variant_cost_min = variant_min self.variant_cost_max = variant_max @@ -2873,6 +2893,9 @@ def update_sale_cost(self, save=True): if max_sell_history is None or cost > max_sell_history: max_sell_history = cost + if self.sale_history_min != min_sell_history or self.sale_history_max != max_sell_history: + self.price_modified = True + self.sale_history_min = min_sell_history self.sale_history_max = max_sell_history