Merge pull request #1679 from matmair/fix-for-1678

fix for part with no bom-price
This commit is contained in:
Oliver 2021-06-18 10:35:59 +10:00 committed by GitHub
commit bb910a09fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 17 deletions

View File

@ -198,18 +198,18 @@ The part single price is the current purchase price for that supplier part."></i
var bomdata = {
labels: [{% for line in bom_parts %}'{{ line.name }}',{% endfor %}],
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',
data: [{% for line in bom_parts %}{{ line.max_price }},{% endfor %}],
backgroundColor: bom_colors,
},
{% 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)

View File

@ -846,17 +846,26 @@ class PartPricingView(PartDetail):
ctx['price_history'] = ret
# 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 [True for a in bom_items if len(set(a['price'])) == 2]:
ctx['bom_parts'] = [{
'name': a['name'],
'min_price': str((a['price'][0] * a['q']) / quantity),
'max_price': str((a['price'][1] * a['q']) / quantity)} for a in bom_items]
ctx['bom_pie_min'] = True
else:
ctx['bom_parts'] = [{
'name': a['name'],
'price': str((a['price'][0] * a['q']) / quantity)} for a in bom_items]
if part.has_bom:
ctx_bom_parts = []
# iterate over all bom-items
for item in part.bom_items.all():
ctx_item = {'name': str(item.sub_part)}
price, qty = item.sub_part.get_price_range(quantity), item.quantity
price_min, price_max = 0, 0
if price: # check if price available
price_min = str((price[0] * qty) / quantity)
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