Simplify allocation display for part page

This commit is contained in:
Oliver 2022-04-27 15:36:44 +10:00
parent 5144821ba7
commit f98225334e
2 changed files with 12 additions and 35 deletions

View File

@ -211,44 +211,18 @@
{% if part.component %}
{% if required_build_order_quantity > 0 %}
<tr>
<td><span class='fas fa-clipboard-list'></span></td>
<td>{% trans "Required for Build Orders" %}</td>
<td>{% decimal required_build_order_quantity %}</td>
</tr>
<tr>
<td><span class='fas fa-dolly'></span></td>
<td><span class='fas fa-tools'></span></td>
<td>{% trans "Allocated to Build Orders" %}</td>
<td>
{% decimal allocated_build_order_quantity %}
{% if allocated_build_order_quantity < required_build_order_quantity %}
<span class='fas fa-times-circle icon-red float-right' title='{% trans "Required quantity has not been allocated" %}'></span>
{% else %}
<span class='fas fa-check-circle icon-green float-right' title='{% trans "Required quantity has been allocated" %}'></span>
{% endif %}
</td>
<td>{% progress_bar allocated_build_order_quantity required_build_order_quantity id='build-order-allocated' max_width='150px' %}</td>
</tr>
{% endif %}
{% endif %}
{% if part.salable %}
{% if required_sales_order_quantity > 0 %}
<tr>
<td><span class='fas fa-clipboard-list'></span></td>
<td>{% trans "Required for Sales Orders" %}</td>
<td>
{% decimal required_sales_order_quantity %}
</td>
</tr>
<tr>
<td><span class='fas fa-dolly'></span></td>
<td><span class='fas fa-truck'></span></td>
<td>{% trans "Allocated to Sales Orders" %}</td>
<td>
{% decimal allocated_sales_order_quantity %}
{% if allocated_sales_order_quantity < required_sales_order_quantity %}
<span class='fas fa-times-circle icon-red float-right' title='{% trans "Required quantity has not been allocated" %}'></span>
{% else %}
<span class='fas fa-check-circle icon-green float-right' title='{% trans "Required quantity has been allocated" %}'></span>
{% endif %}
</td>
<td>{% progress_bar allocated_sales_order_quantity required_sales_order_quantity id='sales-order-allocated' max_width='150px' %}</td>
</tr>
{% endif %}
{% endif %}

View File

@ -352,21 +352,24 @@ def visible_global_settings(*args, **kwargs):
@register.simple_tag()
def progress_bar(val, max, *args, **kwargs):
def progress_bar(val, max_val, *args, **kwargs):
"""
Render a progress bar element
"""
item_id = kwargs.get('id', 'progress-bar')
if val > max:
val = InvenTree.helpers.normalize(val)
max_val = InvenTree.helpers.normalize(max_val)
if val > max_val:
style = 'progress-bar-over'
elif val < max:
elif val < max_val:
style = 'progress-bar-under'
else:
style = ''
percent = float(val / max) * 100
percent = float(val / max_val) * 100
if percent > 100:
percent = 100
@ -383,7 +386,7 @@ def progress_bar(val, max, *args, **kwargs):
html = f"""
<div id='{item_id}' class='progress' style='{" ".join(style_tags)}'>
<div class='progress-bar {style}' role='progressbar' aria-valuemin='0' aria-valuemax='100' style='width:{percent}%'></div>
<div class='progress-value'>{val} / {max}</div>
<div class='progress-value'>{val} / {max_val}</div>
</div>
"""