Refactor: Add "makeIconBadge" javascript function

This commit is contained in:
Oliver Walters 2020-10-24 00:33:30 +11:00
parent ea7b1b65d6
commit b45a11aa3d
5 changed files with 40 additions and 26 deletions

View File

@ -78,6 +78,14 @@ function getImageUrlFromTransfer(transfer) {
return url;
}
function makeIconBadge(icon, title) {
// Construct an 'icon badge' which floats to the right of an object
var html = `<span class='fas ${icon} label-right' title='${title}'></span>`;
return html;
}
function makeIconButton(icon, cls, pk, title, options={}) {
// Construct an 'icon button' using the fontawesome set

View File

@ -567,7 +567,7 @@ class Build(MPTTModel):
required = self.getRequiredQuantity(part, output=output)
allocated = self.getAllocatedQuantity(part, output=output)
return max(required-allocated, 0)
return max(required - allocated, 0)
@property
def required_parts(self):
@ -618,7 +618,6 @@ class Build(MPTTModel):
return items
@property
def can_build(self):
""" Return true if there are enough parts to supply build """

View File

@ -179,11 +179,15 @@ class BuildOutputDelete(AjaxUpdateView):
valid = False
if output:
build.deleteBuildOutput(output)
valid = True
if confirm:
if output:
build.deleteBuildOutput(output)
valid = True
else:
form.non_field_errors = [_('Build or output not specified')]
else:
form.non_field_errors = [_('Build or output not specified')]
form.errors['confirm'] = [_('Confirm unallocation of build stock')]
form.non_field_errors = [_('Check the confirmation box')]
data = {
'form_valid': valid,
@ -191,6 +195,7 @@ class BuildOutputDelete(AjaxUpdateView):
return self.renderJsonResponse(request, form, data)
class BuildUnallocate(AjaxUpdateView):
""" View to un-allocate all parts from a build.

View File

@ -37,13 +37,13 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
{% for allocation in item.sales_order_allocations.all %}
<div class='alert alert-block alert-info'>
{% trans "This stock item is allocated to Sales Order" %} <a href="{% url 'so-detail' allocation.line.order.id %}"><b>#{{ allocation.line.order.reference }}</b></a> ({% trans "Quantity" %}: {% decimal allocation.quantity %})
{% trans "This stock item is allocated to Sales Order" %} <a href="{% url 'so-detail' allocation.line.order.id %}"><b>#{{ allocation.line.order }}</b></a> ({% trans "Quantity" %}: {% decimal allocation.quantity %})
</div>
{% endfor %}
{% for allocation in item.allocations.all %}
<div class='alert alert-block alert-info'>
{% trans "This stock item is allocated to Build" %} <a href="{% url 'build-detail' allocation.build.id %}"><b>#{{ allocation.build.id }}</b></a> ({% trans "Quantity" %}: {% decimal allocation.quantity %})
{% trans "This stock item is allocated to Build" %} <a href="{% url 'build-detail' allocation.build.id %}"><b>#{{ allocation.build }}</b></a> ({% trans "Quantity" %}: {% decimal allocation.quantity %})
</div>
{% endfor %}

View File

@ -276,7 +276,11 @@ function loadStockTable(table, options) {
// URL (optional)
var url = '';
if (row.belongs_to) {
if (row.is_building && row.build) {
// StockItem is currently being built!
text = "{% trans "In production" %}";
url = `/build/${row.build}/`;
} else if (row.belongs_to) {
// StockItem is installed inside a different StockItem
text = `{% trans "Installed in Stock Item" %} ${row.belongs_to}`;
url = `/stock/item/${row.belongs_to}/installed/`;
@ -288,10 +292,6 @@ function loadStockTable(table, options) {
// StockItem has been assigned to a sales order
text = "{% trans "Assigned to Sales Order" %}";
url = `/order/sales-order/${row.sales_order}/`;
} else if (row.is_building && row.build) {
// StockItem is currently being built!
text = "{% trans "In production" %}";
url = `/build/${row.build}/`;
} else if (row.location) {
text = row.location_detail.pathstring;
url = `/stock/location/${row.location}/`;
@ -507,33 +507,35 @@ function loadStockTable(table, options) {
var html = renderLink(val, `/stock/item/${row.pk}/`);
if (row.allocated) {
html += `<span class='fas fa-bookmark label-right' title='{% trans "Stock item has been allocated" %}'></span>`;
if (row.is_building) {
html += makeIconBadge('fa-tools', '{% trans "Stock item is in production" %}');
}
if (row.sales_order) {
// Stock item has been assigned to a sales order
html += makeIconBadge('fa-truck', '{% trans "Stock item assigned to sales order" %}');
} else if (row.customer) {
// StockItem has been assigned to a customer
html += makeIconBadge('fa-user', '{% trans "Stock item assigned to customer" %}');
}
if (row.customer) {
html += `<span class='fas fa-user-tie label-right' title='{% trans "Stock item has been assigned to customer" %}'></span>`;
} else {
if (row.build_order) {
html += `<span class='fas fa-tools label-right' title='{% trans "Stock item was assigned to a build order" %}'></span>`;
} else if (row.sales_order) {
html += `<span class='fas fa-dollar-sign label-right' title='{% trans "Stock item was assigned to a sales order" %}'></span>`;
}
if (row.allocated) {
html += makeIconBadge('fa-bookmark', '{% trans "Stock item has been allocated" %}');
}
if (row.belongs_to) {
html += `<span class='fas fa-box label-right' title='{% trans "Stock item has been installed in another item" %}'></span>`;
html += makeIconBadge('fa-box', '{% trans "Stock item has been installed in another item" %}');
}
// Special stock status codes
// 65 = "REJECTED"
if (row.status == 65) {
html += `<span class='fas fa-times-circle label-right' title='{% trans "Stock item has been rejected" %}'></span>`;
html += makeIconButton('fa-times-circle icon-red', '{% trans "Stock item has been rejected" %}');
}
// 70 = "LOST"
else if (row.status == 70) {
html += `<span class='fas fa-question-circle label-right' title='{% trans "Stock item is lost" %}'></span>`;
html += makeIconButton('fa-question-circle','{% trans "Stock item is lost" %}');
}
if (row.quantity <= 0) {