mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Null units fix (#3663)
* Hide units on part page if units are null * Hide null units in stock table * Hide null units in supplier part table * Hide null units in part tables * Template cleanup * Unit test fix
This commit is contained in:
@ -25,9 +25,9 @@
|
||||
<a href='{{ line.link }}'>{{ line.part.full_name }}</a>{% if part.description %} - <em>{{ part.description }}</em>{% endif %}
|
||||
</td>
|
||||
<td style="text-align: center;">
|
||||
{% decimal line.required %} {% if line.part.units %}{{ line.part.units }}{% endif %}
|
||||
{% decimal line.required %} {% include "part/part_units.html" with part=line.part %}
|
||||
</td>
|
||||
<td style="text-align: center;">{% decimal line.available %} {% if line.part.units %}{{ line.part.units }}{% endif %}</td>
|
||||
<td style="text-align: center;">{% decimal line.available %} {% include "part/part_units.html" with part=line.part %}</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
|
@ -998,7 +998,7 @@ function loadSupplierPartTable(table, url, options) {
|
||||
formatter: function(value, row) {
|
||||
var output = `${value}`;
|
||||
|
||||
if (row.part_detail) {
|
||||
if (row.part_detail && row.part_detail.units) {
|
||||
output += ` ${row.part_detail.units}`;
|
||||
}
|
||||
|
||||
|
@ -574,43 +574,41 @@ function duplicateBom(part_id, options={}) {
|
||||
function partStockLabel(part, options={}) {
|
||||
|
||||
// Prevent literal string 'null' from being displayed
|
||||
if (part.units == null) {
|
||||
part.units = '';
|
||||
}
|
||||
var units = part.units || '';
|
||||
|
||||
if (part.in_stock) {
|
||||
// There IS stock available for this part
|
||||
|
||||
// Is stock "low" (below the 'minimum_stock' quantity)?
|
||||
if ((part.minimum_stock > 0) && (part.minimum_stock > part.in_stock)) {
|
||||
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "Low stock" %}: ${part.in_stock}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "Low stock" %}: ${part.in_stock} ${units}</span>`;
|
||||
} else if (part.unallocated_stock == 0) {
|
||||
if (part.ordering) {
|
||||
// There is no available stock, but stock is on order
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "On Order" %}: ${part.ordering}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "On Order" %}: ${part.ordering} ${units}</span>`;
|
||||
} else if (part.building) {
|
||||
// There is no available stock, but stock is being built
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "Building" %}: ${part.building}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "Building" %}: ${part.building} ${units}</span>`;
|
||||
} else {
|
||||
// There is no available stock at all
|
||||
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "No stock available" %}</span>`;
|
||||
}
|
||||
} else if (part.unallocated_stock < part.in_stock) {
|
||||
// Unallocated quanttiy is less than total quantity
|
||||
return `<span class='badge rounded-pill bg-success ${options.classes}'>{% trans "Available" %}: ${part.unallocated_stock}/${part.in_stock}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-success ${options.classes}'>{% trans "Available" %}: ${part.unallocated_stock}/${part.in_stock} ${units}</span>`;
|
||||
} else {
|
||||
// Stock is completely available
|
||||
return `<span class='badge rounded-pill bg-success ${options.classes}'>{% trans "Available" %}: ${part.unallocated_stock}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-success ${options.classes}'>{% trans "Available" %}: ${part.unallocated_stock} ${units}</span>`;
|
||||
}
|
||||
} else {
|
||||
// There IS NO stock available for this part
|
||||
|
||||
if (part.ordering) {
|
||||
// There is no stock, but stock is on order
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "On Order" %}: ${part.ordering}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "On Order" %}: ${part.ordering} ${units}</span>`;
|
||||
} else if (part.building) {
|
||||
// There is no stock, but stock is being built
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "Building" %}: ${part.building}${part.units}</span>`;
|
||||
return `<span class='badge rounded-pill bg-info ${options.classes}'>{% trans "Building" %}: ${part.building} ${units}</span>`;
|
||||
} else {
|
||||
// There is no stock
|
||||
return `<span class='badge rounded-pill bg-danger ${options.classes}'>{% trans "No Stock" %}</span>`;
|
||||
@ -1324,8 +1322,8 @@ function partGridTile(part) {
|
||||
// Rows for table view
|
||||
var rows = '';
|
||||
|
||||
var units = part.units;
|
||||
var stock = `${part.in_stock} ${part.units}`;
|
||||
var units = part.units || '';
|
||||
var stock = `${part.in_stock} ${units}`;
|
||||
|
||||
if (!part.in_stock) {
|
||||
stock = `<span class='badge rounded-pill bg-danger'>{% trans "No Stock" %}</span>`;
|
||||
|
@ -1764,7 +1764,7 @@ function loadStockTable(table, options) {
|
||||
// Format floating point numbers with this one weird trick
|
||||
val = formatDecimal(value);
|
||||
|
||||
if (row.part_detail) {
|
||||
if (row.part_detail && row.part_detail.units) {
|
||||
val += ` ${row.part_detail.units}`;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user