Skip to content

Commit

Permalink
stop cascade update_pricing if prices didnt change (#5606) (#5607)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Lippert <oliver@lipperts-web.de>
(cherry picked from commit 2f0dbf9)

Co-authored-by: Oliver Lippert <oliver@allesit.de>
  • Loading branch information
github-actions[bot] and lippoliv committed Sep 24, 2023
1 parent 85b8157 commit 978e08f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion InvenTree/part/models.py
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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()

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 978e08f

Please sign in to comment.