mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add settings for controlling variant pricing (#3987)
* Add settings for controlling variant pricing * Select whether to use variant pricing * Add setting to ignore inactive variants * Update variant pricing table
This commit is contained in:
parent
1058a7c490
commit
4f5adef402
@ -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'),
|
||||
|
@ -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:
|
||||
|
@ -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" %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user