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:
Oliver 2022-09-08 15:18:43 +10:00 committed by GitHub
parent b827f14bf6
commit 875dda7e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 23 deletions

View File

@ -149,7 +149,7 @@ src="{% static 'img/blank_image.png' %}"
<tr>
<td><span class='fas fa-box'></span></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>
{% endif %}
{% if part.note %}

View File

@ -187,7 +187,7 @@
<tr>
<td><h5><span class='fas fa-boxes'></span></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>
<td><span class='fas fa-map-marker-alt'></span></td>
@ -198,14 +198,14 @@
<tr>
<td><span class='fas fa-flag'></span></td>
<td>{% trans "Minimum Stock" %}</td>
<td>{{ part.minimum_stock }} {{ part.units }}</td>
<td>{{ part.minimum_stock }} {% include "part/part_units.html" %}</td>
</tr>
{% endif %}
{% if on_order > 0 %}
<tr>
<td><span class='fas fa-shopping-cart'></span></td>
<td>{% trans "On Order" %}</td>
<td>{% decimal on_order %} {{ part.units }}</td>
<td>{% decimal on_order %} {% include "part/part_units.html" %}/td>
</tr>
{% endif %}
{% if part.component %}

View File

@ -0,0 +1 @@
{% if part.units %}{{ part.units }}{% endif %}

View File

@ -1,7 +1,7 @@
{% load inventree_extras %}
{% load i18n %}
{% decimal total_stock %} {{ part.units }}
{% decimal total_stock %} {% include "part/part_units.html" %}
{% if total_stock == 0 %}
<span class='badge badge-right rounded-pill bg-danger'>{% trans "No Stock" %}</span>

View File

@ -348,7 +348,7 @@
<h5>{% trans "Available Quantity" %}</h5>
</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>
{% endif %}
</tr>

View File

@ -49,7 +49,7 @@ class StockDetailTest(StockViewTestCase):
# Quantity
self.assertIn('<h5>Available Quantity</h5>', html)
self.assertIn('<h5>4000 </h5>', html)
self.assertIn('<h5>4000', html)
# Batch code
self.assertIn('Batch', html)

View File

@ -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 %}

View File

@ -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}`;
}

View File

@ -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>`;

View File

@ -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}`;
}
}