From a54760b21964701b61076392e6085dea976c1227 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 23:44:43 +1000 Subject: [PATCH] Improve pricing display --- .../part/templates/part/part_pricing.html | 60 +++++++++++++++---- InvenTree/part/views.py | 30 ++++++++-- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/InvenTree/part/templates/part/part_pricing.html b/InvenTree/part/templates/part/part_pricing.html index bfff341049..6d82549bb2 100644 --- a/InvenTree/part/templates/part/part_pricing.html +++ b/InvenTree/part/templates/part/part_pricing.html @@ -6,37 +6,77 @@ Calculate pricing information for {{ part }}. +

Quantity

- + - + - {% if buy_price %} +
Part{{ part }}{{ part }}
Quantity{{ quantity }}{{ quantity }}
+ {% if part.supplier_count > 0 %} +

Supplier Pricing

+ + {% if min_total_buy_price %} - - + + + + + {% if quantity > 1 %} + + + + {% endif %} - {% if bom_price %} + {% else %} - - + + {% endif %} +
Buy Cost{{ buy_price }}Unit CostMin: {{ min_unit_buy_price }}Max: {{ max_unit_buy_price }}
Total CostMin: {{ min_total_buy_price }}Max: {{ max_total_buy_price }}
BOM Cost{{ bom_price }} + No supplier pricing available +
+ {% endif %} + + {% if part.bom_count > 0 %} +

BOM Pricing

+ + {% if min_total_bom_price %} + + + + + + {% if quantity > 1 %} + + + + + + {% endif %} {% if part.has_complete_bom_pricing == False %} - {% endif %} + {% else %} + + + {% endif %}
Unit CostMin: {{ min_unit_bom_price }}Max: {{ max_unit_bom_price }}
Total CostMin: {{ min_total_bom_price }}Max: {{ max_total_bom_price }}
+ Note: BOM pricing is incomplete for this part
+ No BOM pricing available +
+ {% endif %} -{% if buy_price or bom_price %} +{% if min_unit_buy_price or min_unit_bom_price %} {% else %}
No pricing information is available for this part. diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 7a7a85ae2d..d5824b2dab 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -577,14 +577,32 @@ class PartPricing(AjaxView): if part is None: return ctx - buy_price = part.get_price_info(quantity, bom=False) - bom_price = part.get_price_info(quantity, buy=False) + # Supplier pricing information + if part.supplier_count > 0: + min_buy_price = part.get_min_supplier_price(quantity) + max_buy_price = part.get_max_supplier_price(quantity) - if buy_price: - ctx['buy_price'] = buy_price + if min_buy_price: + ctx['min_total_buy_price'] = min_buy_price + ctx['min_unit_buy_price'] = min_buy_price / quantity - if bom_price: - ctx['bom_price'] = bom_price + if max_buy_price: + ctx['max_total_buy_price'] = max_buy_price + ctx['max_unit_buy_price'] = max_buy_price / quantity + + # BOM pricing information + if part.bom_count > 0: + + min_bom_price = part.get_min_bom_price(quantity) + max_bom_price = part.get_max_bom_price(quantity) + + if min_bom_price: + ctx['min_total_bom_price'] = min_bom_price + ctx['min_unit_bom_price'] = min_bom_price / quantity + + if max_bom_price: + ctx['max_total_bom_price'] = max_bom_price + ctx['max_unit_bom_price'] = max_bom_price / quantity return ctx