mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor: Add "makeIconBadge" javascript function
This commit is contained in:
parent
ea7b1b65d6
commit
b45a11aa3d
@ -78,6 +78,14 @@ function getImageUrlFromTransfer(transfer) {
|
|||||||
return url;
|
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={}) {
|
function makeIconButton(icon, cls, pk, title, options={}) {
|
||||||
// Construct an 'icon button' using the fontawesome set
|
// Construct an 'icon button' using the fontawesome set
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ class Build(MPTTModel):
|
|||||||
required = self.getRequiredQuantity(part, output=output)
|
required = self.getRequiredQuantity(part, output=output)
|
||||||
allocated = self.getAllocatedQuantity(part, output=output)
|
allocated = self.getAllocatedQuantity(part, output=output)
|
||||||
|
|
||||||
return max(required-allocated, 0)
|
return max(required - allocated, 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def required_parts(self):
|
def required_parts(self):
|
||||||
@ -618,7 +618,6 @@ class Build(MPTTModel):
|
|||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def can_build(self):
|
def can_build(self):
|
||||||
""" Return true if there are enough parts to supply build """
|
""" Return true if there are enough parts to supply build """
|
||||||
|
@ -179,11 +179,15 @@ class BuildOutputDelete(AjaxUpdateView):
|
|||||||
|
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
|
if confirm:
|
||||||
if output:
|
if output:
|
||||||
build.deleteBuildOutput(output)
|
build.deleteBuildOutput(output)
|
||||||
valid = True
|
valid = True
|
||||||
else:
|
else:
|
||||||
form.non_field_errors = [_('Build or output not specified')]
|
form.non_field_errors = [_('Build or output not specified')]
|
||||||
|
else:
|
||||||
|
form.errors['confirm'] = [_('Confirm unallocation of build stock')]
|
||||||
|
form.non_field_errors = [_('Check the confirmation box')]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'form_valid': valid,
|
'form_valid': valid,
|
||||||
@ -191,6 +195,7 @@ class BuildOutputDelete(AjaxUpdateView):
|
|||||||
|
|
||||||
return self.renderJsonResponse(request, form, data)
|
return self.renderJsonResponse(request, form, data)
|
||||||
|
|
||||||
|
|
||||||
class BuildUnallocate(AjaxUpdateView):
|
class BuildUnallocate(AjaxUpdateView):
|
||||||
""" View to un-allocate all parts from a build.
|
""" View to un-allocate all parts from a build.
|
||||||
|
|
||||||
|
@ -37,13 +37,13 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
|
|||||||
|
|
||||||
{% for allocation in item.sales_order_allocations.all %}
|
{% for allocation in item.sales_order_allocations.all %}
|
||||||
<div class='alert alert-block alert-info'>
|
<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>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for allocation in item.allocations.all %}
|
{% for allocation in item.allocations.all %}
|
||||||
<div class='alert alert-block alert-info'>
|
<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>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
@ -276,7 +276,11 @@ function loadStockTable(table, options) {
|
|||||||
// URL (optional)
|
// URL (optional)
|
||||||
var url = '';
|
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
|
// StockItem is installed inside a different StockItem
|
||||||
text = `{% trans "Installed in Stock Item" %} ${row.belongs_to}`;
|
text = `{% trans "Installed in Stock Item" %} ${row.belongs_to}`;
|
||||||
url = `/stock/item/${row.belongs_to}/installed/`;
|
url = `/stock/item/${row.belongs_to}/installed/`;
|
||||||
@ -288,10 +292,6 @@ function loadStockTable(table, options) {
|
|||||||
// StockItem has been assigned to a sales order
|
// StockItem has been assigned to a sales order
|
||||||
text = "{% trans "Assigned to Sales Order" %}";
|
text = "{% trans "Assigned to Sales Order" %}";
|
||||||
url = `/order/sales-order/${row.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) {
|
} else if (row.location) {
|
||||||
text = row.location_detail.pathstring;
|
text = row.location_detail.pathstring;
|
||||||
url = `/stock/location/${row.location}/`;
|
url = `/stock/location/${row.location}/`;
|
||||||
@ -507,33 +507,35 @@ function loadStockTable(table, options) {
|
|||||||
|
|
||||||
var html = renderLink(val, `/stock/item/${row.pk}/`);
|
var html = renderLink(val, `/stock/item/${row.pk}/`);
|
||||||
|
|
||||||
if (row.allocated) {
|
if (row.is_building) {
|
||||||
html += `<span class='fas fa-bookmark label-right' title='{% trans "Stock item has been allocated" %}'></span>`;
|
html += makeIconBadge('fa-tools', '{% trans "Stock item is in production" %}');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row.customer) {
|
if (row.sales_order) {
|
||||||
html += `<span class='fas fa-user-tie label-right' title='{% trans "Stock item has been assigned to customer" %}'></span>`;
|
// Stock item has been assigned to a sales order
|
||||||
} else {
|
html += makeIconBadge('fa-truck', '{% trans "Stock item assigned to sales order" %}');
|
||||||
if (row.build_order) {
|
} else if (row.customer) {
|
||||||
html += `<span class='fas fa-tools label-right' title='{% trans "Stock item was assigned to a build order" %}'></span>`;
|
// StockItem has been assigned to a customer
|
||||||
} else if (row.sales_order) {
|
html += makeIconBadge('fa-user', '{% trans "Stock item assigned to customer" %}');
|
||||||
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) {
|
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
|
// Special stock status codes
|
||||||
|
|
||||||
// 65 = "REJECTED"
|
// 65 = "REJECTED"
|
||||||
if (row.status == 65) {
|
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"
|
// 70 = "LOST"
|
||||||
else if (row.status == 70) {
|
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) {
|
if (row.quantity <= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user