diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 1a8f0cf373..1ab30270ed 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1105,6 +1105,20 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'validator': bool, }, + 'PRICING_USE_VARIANT_PRICING': { + 'name': _('Use Variant Pricing'), + 'description': _('Include variant pricing in overall pricing calculations'), + 'default': True, + 'validator': bool, + }, + + 'PRICING_ACTIVE_VARIANTS': { + 'name': _('Active Variants Only'), + 'description': _('Only use active variant parts for calculating variant pricing'), + 'default': False, + '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 51c9ec1461..ce49ad56dd 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2571,10 +2571,17 @@ class PartPricing(models.Model): variant_min = None variant_max = None + active_only = InvenTreeSetting.get_setting('PRICING_ACTIVE_VARIANTS', False) + if self.part.is_template: variants = self.part.get_descendants(include_self=False) for v in variants: + + if active_only and not v.active: + # Ignore inactive variant parts + continue + v_min = self.convert(v.pricing.overall_min) v_max = self.convert(v.pricing.overall_max) @@ -2605,20 +2612,22 @@ class PartPricing(models.Model): self.bom_cost_min, self.purchase_cost_min, self.internal_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) + if InvenTreeSetting.get_setting('PRICING_USE_VARIANT_PRICING', True): + min_costs.append(self.variant_cost_min) + max_costs.append(self.variant_cost_max) + # Calculate overall minimum cost for cost in min_costs: if cost is None: diff --git a/InvenTree/templates/InvenTree/settings/pricing.html b/InvenTree/templates/InvenTree/settings/pricing.html index 5fe830efd6..efb04cc773 100644 --- a/InvenTree/templates/InvenTree/settings/pricing.html +++ b/InvenTree/templates/InvenTree/settings/pricing.html @@ -16,6 +16,9 @@ {% 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_USE_VARIANT_PRICING" icon='fa-check-circle' %} + {% include "InvenTree/settings/setting.html" with key="PRICING_ACTIVE_VARIANTS" %} + diff --git a/InvenTree/templates/js/translated/pricing.js b/InvenTree/templates/js/translated/pricing.js index 66f9ed7c8c..66c9f2413f 100644 --- a/InvenTree/templates/js/translated/pricing.js +++ b/InvenTree/templates/js/translated/pricing.js @@ -695,6 +695,11 @@ function loadVariantPricingChart(options={}) { options.params.ancestor = part; + if (global_settings.PRICING_ACTIVE_VARIANTS) { + // Filter variants by "active" status + options.params.active = true; + } + table.inventreeTable({ url: '{% url "api-part-list" %}', name: 'variantpricingtable',