mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +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:
parent
b827f14bf6
commit
875dda7e59
@ -149,7 +149,7 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-box'></span></td>
|
<td><span class='fas fa-box'></span></td>
|
||||||
<td>{% trans "Pack Quantity" %}</td>
|
<td>{% trans "Pack Quantity" %}</td>
|
||||||
<td>{% decimal part.pack_size %}{% if part.part.units %} {{ part.part.units }}{% endif %}</td>
|
<td>{% decimal part.pack_size %} {% include "part/part_units.html" with part=part.part %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if part.note %}
|
{% if part.note %}
|
||||||
|
@ -187,7 +187,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><h5><span class='fas fa-boxes'></span></h5></td>
|
<td><h5><span class='fas fa-boxes'></span></h5></td>
|
||||||
<td><h5>{% trans "Available Stock" %}</h5></td>
|
<td><h5>{% trans "Available Stock" %}</h5></td>
|
||||||
<td><h5>{% decimal available %}{% if part.units %} {{ part.units }}{% endif %}</h5></td>
|
<td><h5>{% decimal available %} {% include "part/part_units.html" %}</h5></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-map-marker-alt'></span></td>
|
<td><span class='fas fa-map-marker-alt'></span></td>
|
||||||
@ -198,14 +198,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-flag'></span></td>
|
<td><span class='fas fa-flag'></span></td>
|
||||||
<td>{% trans "Minimum Stock" %}</td>
|
<td>{% trans "Minimum Stock" %}</td>
|
||||||
<td>{{ part.minimum_stock }} {{ part.units }}</td>
|
<td>{{ part.minimum_stock }} {% include "part/part_units.html" %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if on_order > 0 %}
|
{% if on_order > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-shopping-cart'></span></td>
|
<td><span class='fas fa-shopping-cart'></span></td>
|
||||||
<td>{% trans "On Order" %}</td>
|
<td>{% trans "On Order" %}</td>
|
||||||
<td>{% decimal on_order %} {{ part.units }}</td>
|
<td>{% decimal on_order %} {% include "part/part_units.html" %}/td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if part.component %}
|
{% if part.component %}
|
||||||
|
1
InvenTree/part/templates/part/part_units.html
Normal file
1
InvenTree/part/templates/part/part_units.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
{% if part.units %}{{ part.units }}{% endif %}
|
@ -1,7 +1,7 @@
|
|||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% decimal total_stock %} {{ part.units }}
|
{% decimal total_stock %} {% include "part/part_units.html" %}
|
||||||
|
|
||||||
{% if total_stock == 0 %}
|
{% if total_stock == 0 %}
|
||||||
<span class='badge badge-right rounded-pill bg-danger'>{% trans "No Stock" %}</span>
|
<span class='badge badge-right rounded-pill bg-danger'>{% trans "No Stock" %}</span>
|
||||||
|
@ -348,7 +348,7 @@
|
|||||||
<h5>{% trans "Available Quantity" %}</h5>
|
<h5>{% trans "Available Quantity" %}</h5>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<h5>{% if item.quantity != available %}{% decimal available %} / {% endif %}{% decimal item.quantity %} {% if item.part.units %}{{ item.part.units }}{% endif %}</h5>
|
<h5>{% if item.quantity != available %}{% decimal available %} / {% endif %}{% decimal item.quantity %} {% include "part/part_units.html" with part=item.part %}</h5>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -49,7 +49,7 @@ class StockDetailTest(StockViewTestCase):
|
|||||||
|
|
||||||
# Quantity
|
# Quantity
|
||||||
self.assertIn('<h5>Available Quantity</h5>', html)
|
self.assertIn('<h5>Available Quantity</h5>', html)
|
||||||
self.assertIn('<h5>4000 </h5>', html)
|
self.assertIn('<h5>4000', html)
|
||||||
|
|
||||||
# Batch code
|
# Batch code
|
||||||
self.assertIn('Batch', html)
|
self.assertIn('Batch', html)
|
||||||
|
@ -25,9 +25,9 @@
|
|||||||
<a href='{{ line.link }}'>{{ line.part.full_name }}</a>{% if part.description %} - <em>{{ part.description }}</em>{% endif %}
|
<a href='{{ line.link }}'>{{ line.part.full_name }}</a>{% if part.description %} - <em>{{ part.description }}</em>{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<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>
|
||||||
<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>
|
</tr>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -998,7 +998,7 @@ function loadSupplierPartTable(table, url, options) {
|
|||||||
formatter: function(value, row) {
|
formatter: function(value, row) {
|
||||||
var output = `${value}`;
|
var output = `${value}`;
|
||||||
|
|
||||||
if (row.part_detail) {
|
if (row.part_detail && row.part_detail.units) {
|
||||||
output += ` ${row.part_detail.units}`;
|
output += ` ${row.part_detail.units}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,43 +574,41 @@ function duplicateBom(part_id, options={}) {
|
|||||||
function partStockLabel(part, options={}) {
|
function partStockLabel(part, options={}) {
|
||||||
|
|
||||||
// Prevent literal string 'null' from being displayed
|
// Prevent literal string 'null' from being displayed
|
||||||
if (part.units == null) {
|
var units = part.units || '';
|
||||||
part.units = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part.in_stock) {
|
if (part.in_stock) {
|
||||||
// There IS stock available for this part
|
// There IS stock available for this part
|
||||||
|
|
||||||
// Is stock "low" (below the 'minimum_stock' quantity)?
|
// Is stock "low" (below the 'minimum_stock' quantity)?
|
||||||
if ((part.minimum_stock > 0) && (part.minimum_stock > part.in_stock)) {
|
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) {
|
} else if (part.unallocated_stock == 0) {
|
||||||
if (part.ordering) {
|
if (part.ordering) {
|
||||||
// There is no available stock, but stock is on order
|
// 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) {
|
} else if (part.building) {
|
||||||
// There is no available stock, but stock is being built
|
// 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 {
|
} else {
|
||||||
// There is no available stock at all
|
// There is no available stock at all
|
||||||
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "No stock available" %}</span>`;
|
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "No stock available" %}</span>`;
|
||||||
}
|
}
|
||||||
} else if (part.unallocated_stock < part.in_stock) {
|
} else if (part.unallocated_stock < part.in_stock) {
|
||||||
// Unallocated quanttiy is less than total quantity
|
// 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 {
|
} else {
|
||||||
// Stock is completely available
|
// 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 {
|
} else {
|
||||||
// There IS NO stock available for this part
|
// There IS NO stock available for this part
|
||||||
|
|
||||||
if (part.ordering) {
|
if (part.ordering) {
|
||||||
// There is no stock, but stock is on order
|
// 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) {
|
} else if (part.building) {
|
||||||
// There is no stock, but stock is being built
|
// 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 {
|
} else {
|
||||||
// There is no stock
|
// There is no stock
|
||||||
return `<span class='badge rounded-pill bg-danger ${options.classes}'>{% trans "No Stock" %}</span>`;
|
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
|
// Rows for table view
|
||||||
var rows = '';
|
var rows = '';
|
||||||
|
|
||||||
var units = part.units;
|
var units = part.units || '';
|
||||||
var stock = `${part.in_stock} ${part.units}`;
|
var stock = `${part.in_stock} ${units}`;
|
||||||
|
|
||||||
if (!part.in_stock) {
|
if (!part.in_stock) {
|
||||||
stock = `<span class='badge rounded-pill bg-danger'>{% trans "No Stock" %}</span>`;
|
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
|
// Format floating point numbers with this one weird trick
|
||||||
val = formatDecimal(value);
|
val = formatDecimal(value);
|
||||||
|
|
||||||
if (row.part_detail) {
|
if (row.part_detail && row.part_detail.units) {
|
||||||
val += ` ${row.part_detail.units}`;
|
val += ` ${row.part_detail.units}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user