From f0325fe30fac874f5fb1f4888c6979605cc30f02 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 13 Aug 2021 17:50:41 +0200 Subject: [PATCH] view BOMpricing range Closes #1889 --- .../part/templates/part/part_pricing.html | 15 ++++++++++ InvenTree/part/templates/part/prices.html | 19 ++++++++++++ InvenTree/part/views.py | 29 ++++++++++++------- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/InvenTree/part/templates/part/part_pricing.html b/InvenTree/part/templates/part/part_pricing.html index ce55124bd9..be80efe1e7 100644 --- a/InvenTree/part/templates/part/part_pricing.html +++ b/InvenTree/part/templates/part/part_pricing.html @@ -60,6 +60,21 @@ Max: {% include "price.html" with price=max_total_bom_price %} {% endif %} + {% if min_total_bom_purchase_price %} + + {% trans 'Unit Purchase Price' %} + Min: {% include "price.html" with price=min_unit_bom_purchase_price %} + Max: {% include "price.html" with price=max_unit_bom_purchase_price %} + + {% if quantity > 1 %} + + {% trans 'Total Purchase Price' %} + Min: {% include "price.html" with price=min_total_bom_purchase_price %} + Max: {% include "price.html" with price=max_total_bom_purchase_price %} + + {% endif %} + {% endif %} + {% if part.has_complete_bom_pricing == False %} diff --git a/InvenTree/part/templates/part/prices.html b/InvenTree/part/templates/part/prices.html index e498bc09ba..57967bf1d8 100644 --- a/InvenTree/part/templates/part/prices.html +++ b/InvenTree/part/templates/part/prices.html @@ -61,6 +61,25 @@ Max: {% include "price.html" with price=max_total_bom_price %} {% endif %} + + + {% if min_total_bom_purchase_price %} + + + {% trans 'Unit Purchase Price' %} + Min: {% include "price.html" with price=min_unit_bom_purchase_price %} + Max: {% include "price.html" with price=max_unit_bom_purchase_price %} + + {% if quantity > 1 %} + + + {% trans 'Total Purchase Price' %} + Min: {% include "price.html" with price=min_total_bom_purchase_price %} + Max: {% include "price.html" with price=max_total_bom_purchase_price %} + + {% endif %} + {% endif %} + {% if part.has_complete_bom_pricing == False %} diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 0e06678694..5d7a083e9b 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1351,6 +1351,7 @@ class PartPricing(AjaxView): use_internal = InvenTreeSetting.get_setting('PART_BOM_USE_INTERNAL_PRICE', False) bom_price = part.get_bom_price_range(quantity, internal=use_internal) + purchase_price = part.get_bom_price_range(quantity, purchase=True) if bom_price is not None: min_bom_price, max_bom_price = bom_price @@ -1358,19 +1359,27 @@ class PartPricing(AjaxView): min_bom_price /= scaler max_bom_price /= scaler - min_unit_bom_price = round(min_bom_price / quantity, 3) - max_unit_bom_price = round(max_bom_price / quantity, 3) - - min_bom_price = round(min_bom_price, 3) - max_bom_price = round(max_bom_price, 3) - if min_bom_price: - ctx['min_total_bom_price'] = min_bom_price - ctx['min_unit_bom_price'] = min_unit_bom_price + ctx['min_total_bom_price'] = round(min_bom_price, 3) + ctx['min_unit_bom_price'] = round(min_bom_price / quantity, 3) if max_bom_price: - ctx['max_total_bom_price'] = max_bom_price - ctx['max_unit_bom_price'] = max_unit_bom_price + ctx['max_total_bom_price'] = round(max_bom_price, 3) + ctx['max_unit_bom_price'] = round(max_bom_price / quantity, 3) + + if purchase_price is not None: + min_bom_purchase_price, max_bom_purchase_price = purchase_price + + min_bom_purchase_price /= scaler + max_bom_purchase_price /= scaler + if min_bom_purchase_price: + ctx['min_total_bom_purchase_price'] = round(min_bom_purchase_price, 3) + ctx['min_unit_bom_purchase_price'] = round(min_bom_purchase_price / quantity, 3) + + if max_bom_purchase_price: + ctx['max_total_bom_purchase_price'] = round(max_bom_purchase_price, 3) + ctx['max_unit_bom_purchase_price'] = round(max_bom_purchase_price / quantity, 3) + # internal part pricing information internal_part_price = part.get_internal_price(quantity)