From 8cd782dc8fa6e7cd15b7892d37435035ce118fc9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 22 Nov 2022 16:28:55 +1100 Subject: [PATCH] Supplier pricing override (#3988) * Adds new option for overriding supplier price break pricing data * Add logic for overriding supplier part pricing with historical information * Prevent caching --- InvenTree/common/models.py | 7 +++++++ InvenTree/part/models.py | 14 ++++++++++---- .../templates/InvenTree/settings/pricing.html | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 1ab30270ed..3fda27499a 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1105,6 +1105,13 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'validator': bool, }, + 'PRICING_PURCHASE_HISTORY_OVERRIDES_SUPPLIER': { + 'name': _('Purchase History Override'), + 'description': _('Historical purchase order pricing overrides supplier price breaks'), + 'default': False, + 'validator': bool, + }, + 'PRICING_USE_VARIANT_PRICING': { 'name': _('Use Variant Pricing'), 'description': _('Include variant pricing in overall pricing calculations'), diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index ce49ad56dd..4c77306fe0 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2620,11 +2620,17 @@ class PartPricing(models.Model): self.internal_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) + purchase_history_override = InvenTreeSetting.get_setting('PRICING_PURCHASE_HISTORY_OVERRIDES_SUPPLIER', False, cache=False) - if InvenTreeSetting.get_setting('PRICING_USE_VARIANT_PRICING', True): + if InvenTreeSetting.get_setting('PRICING_USE_SUPPLIER_PRICING', True, cache=False): + # Add supplier pricing data, *unless* historical pricing information should override + if self.purchase_cost_min is None or not purchase_history_override: + min_costs.append(self.supplier_price_min) + + if self.purchase_cost_max is None or not purchase_history_override: + max_costs.append(self.supplier_price_max) + + if InvenTreeSetting.get_setting('PRICING_USE_VARIANT_PRICING', True, cache=False): min_costs.append(self.variant_cost_min) max_costs.append(self.variant_cost_max) diff --git a/InvenTree/templates/InvenTree/settings/pricing.html b/InvenTree/templates/InvenTree/settings/pricing.html index efb04cc773..f05103e95e 100644 --- a/InvenTree/templates/InvenTree/settings/pricing.html +++ b/InvenTree/templates/InvenTree/settings/pricing.html @@ -16,6 +16,7 @@ {% 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' %} + {% include "InvenTree/settings/setting.html" with key="PRICING_PURCHASE_HISTORY_OVERRIDES_SUPPLIER" icon='fa-shopping-cart' %} {% include "InvenTree/settings/setting.html" with key="PRICING_USE_VARIANT_PRICING" icon='fa-check-circle' %} {% include "InvenTree/settings/setting.html" with key="PRICING_ACTIVE_VARIANTS" %}