mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1679 from matmair/fix-for-1678
fix for part with no bom-price
This commit is contained in:
commit
bb910a09fb
@ -198,18 +198,18 @@ The part single price is the current purchase price for that supplier part."></i
|
|||||||
var bomdata = {
|
var bomdata = {
|
||||||
labels: [{% for line in bom_parts %}'{{ line.name }}',{% endfor %}],
|
labels: [{% for line in bom_parts %}'{{ line.name }}',{% endfor %}],
|
||||||
datasets: [
|
datasets: [
|
||||||
{% if bom_pie_min %}
|
{
|
||||||
|
label: 'Price',
|
||||||
|
data: [{% for line in bom_parts %}{{ line.min_price }},{% endfor %}],
|
||||||
|
backgroundColor: bom_colors,
|
||||||
|
},
|
||||||
|
{% if bom_pie_max %}
|
||||||
{
|
{
|
||||||
label: 'Max Price',
|
label: 'Max Price',
|
||||||
data: [{% for line in bom_parts %}{{ line.max_price }},{% endfor %}],
|
data: [{% for line in bom_parts %}{{ line.max_price }},{% endfor %}],
|
||||||
backgroundColor: bom_colors,
|
backgroundColor: bom_colors,
|
||||||
},
|
},
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{
|
|
||||||
label: 'Price',
|
|
||||||
data: [{% for line in bom_parts %}{% if bom_pie_min %}{{ line.min_price }}{% else %}{{ line.price }}{% endif%},{% endfor %}],
|
|
||||||
backgroundColor: bom_colors,
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
var BomChart = loadBomChart(document.getElementById('BomChart'), bomdata)
|
var BomChart = loadBomChart(document.getElementById('BomChart'), bomdata)
|
||||||
|
@ -846,17 +846,26 @@ class PartPricingView(PartDetail):
|
|||||||
ctx['price_history'] = ret
|
ctx['price_history'] = ret
|
||||||
|
|
||||||
# BOM Information for Pie-Chart
|
# BOM Information for Pie-Chart
|
||||||
bom_items = [{'name': str(a.sub_part), 'price': a.sub_part.get_price_range(quantity), 'q': a.quantity} for a in part.bom_items.all()]
|
if part.has_bom:
|
||||||
if [True for a in bom_items if len(set(a['price'])) == 2]:
|
ctx_bom_parts = []
|
||||||
ctx['bom_parts'] = [{
|
# iterate over all bom-items
|
||||||
'name': a['name'],
|
for item in part.bom_items.all():
|
||||||
'min_price': str((a['price'][0] * a['q']) / quantity),
|
ctx_item = {'name': str(item.sub_part)}
|
||||||
'max_price': str((a['price'][1] * a['q']) / quantity)} for a in bom_items]
|
price, qty = item.sub_part.get_price_range(quantity), item.quantity
|
||||||
ctx['bom_pie_min'] = True
|
|
||||||
else:
|
price_min, price_max = 0, 0
|
||||||
ctx['bom_parts'] = [{
|
if price: # check if price available
|
||||||
'name': a['name'],
|
price_min = str((price[0] * qty) / quantity)
|
||||||
'price': str((a['price'][0] * a['q']) / quantity)} for a in bom_items]
|
if len(set(price)) == 2: # min and max-price present
|
||||||
|
price_max = str((price[1] * qty) / quantity)
|
||||||
|
ctx['bom_pie_max'] = True # enable showing max prices in bom
|
||||||
|
|
||||||
|
ctx_item['max_price'] = price_min
|
||||||
|
ctx_item['min_price'] = price_max if price_max else price_min
|
||||||
|
ctx_bom_parts.append(ctx_item)
|
||||||
|
|
||||||
|
# add to global context
|
||||||
|
ctx['bom_parts'] = ctx_bom_parts
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user