From 1e1662ef0fe63653c58fb0c072a0cd608ddfbf7d Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Nov 2022 09:27:07 +1100 Subject: [PATCH] Add setting to determine if supplier price breaks are used in overall price calculations (#3943) --- InvenTree/common/models.py | 7 +++++ InvenTree/part/models.py | 30 +++++++++++-------- .../templates/InvenTree/settings/pricing.html | 1 + 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index e15de0c6c9..ccf71673d4 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1093,6 +1093,13 @@ class InvenTreeSetting(BaseInvenTreeSetting): ] }, + 'PRICING_USE_SUPPLIER_PRICING': { + 'name': _('Use Supplier Pricing'), + 'description': _('Include supplier price breaks in overall pricing calculations'), + 'default': True, + 'validator': bool, + }, + 'PRICING_UPDATE_DAYS': { 'name': _('Pricing Rebuild Time'), 'description': _('Number of days before part pricing is automatically updated'), diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 2aaf771158..8e5d42add0 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2575,14 +2575,26 @@ class PartPricing(models.Model): overall_min = None overall_max = None - # Calculate overall minimum cost - for cost in [ + min_costs = [ self.bom_cost_min, self.purchase_cost_min, self.internal_cost_min, - self.supplier_price_min, - self.variant_cost_min, - ]: + self.variant_cost_min + ] + + max_costs = [ + self.bom_cost_max, + self.purchase_cost_max, + self.internal_cost_max, + self.variant_cost_max + ] + + if InvenTreeSetting.get_setting('PRICING_USE_SUPPLIER_PRICING', True): + min_costs.append(self.supplier_price_min) + max_costs.append(self.supplier_price_max) + + # Calculate overall minimum cost + for cost in min_costs: if cost is None: continue @@ -2593,13 +2605,7 @@ class PartPricing(models.Model): overall_min = cost # Calculate overall maximum cost - for cost in [ - self.bom_cost_max, - self.purchase_cost_max, - self.internal_cost_max, - self.supplier_price_max, - self.variant_cost_max, - ]: + for cost in max_costs: if cost is None: continue diff --git a/InvenTree/templates/InvenTree/settings/pricing.html b/InvenTree/templates/InvenTree/settings/pricing.html index 8fa740a487..5fe830efd6 100644 --- a/InvenTree/templates/InvenTree/settings/pricing.html +++ b/InvenTree/templates/InvenTree/settings/pricing.html @@ -15,6 +15,7 @@ {% include "InvenTree/settings/setting.html" with key="PART_BOM_USE_INTERNAL_PRICE" %} {% include "InvenTree/settings/setting.html" with key="PRICING_DECIMAL_PLACES" %} {% include "InvenTree/settings/setting.html" with key="PRICING_UPDATE_DAYS" icon='fa-calendar-alt' %} + {% include "InvenTree/settings/setting.html" with key="PRICING_USE_SUPPLIER_PRICING" icon='fa-check-circle' %}