2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

SupplierPart availability (#3148)

* Adds new fields to the SupplierPart model:

- available
- availability_updated

* Allow availability_updated field to be blank

* Revert "Remove stat context variables"

This reverts commit 0989c308d0.

* Increment API version

* Adds availability information to the SupplierPart API serializer

- If the 'available' field is updated, the current date is added to the availability_updated field

* Add 'available' field to SupplierPart table

* More JS refactoring

* Add unit testing for specifying availability via the API

* Display availability data on the SupplierPart detail page

* Add ability to set 'available' quantity from the SupplierPart detail page

* Revert "Revert "Remove stat context variables""

This reverts commit 3f98037f79.
This commit is contained in:
Oliver
2022-06-08 21:49:07 +10:00
committed by GitHub
parent a8a543755f
commit 258957c14c
11 changed files with 272 additions and 26 deletions

View File

@ -1010,7 +1010,7 @@ function loadBomTable(table, options={}) {
can_build = available / row.quantity;
}
return +can_build.toFixed(2);
return formatDecimal(can_build, 2);
},
sorter: function(valA, valB, rowA, rowB) {
// Function to sort the "can build" quantity

View File

@ -795,7 +795,7 @@ function sumAllocationsForBomRow(bom_row, allocations) {
quantity += allocation.quantity;
});
return parseFloat(quantity).toFixed(15);
return formatDecimal(quantity, 10);
}
@ -1490,8 +1490,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
// Store the required quantity in the row data
// Prevent weird rounding issues
row.required = parseFloat(quantity.toFixed(15));
row.required = formatDecimal(quantity, 15);
return row.required;
}
@ -2043,7 +2042,7 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
}
// Ensure the quantity sent to the form field is correctly formatted
remaining = parseFloat(remaining.toFixed(15));
remaining = formatDecimal(remaining, 15);
// We only care about entries which are not yet fully allocated
if (remaining > 0) {

View File

@ -189,14 +189,16 @@ function createSupplierPart(options={}) {
function editSupplierPart(part, options={}) {
var fields = supplierPartFields();
var fields = options.fields || supplierPartFields();
// Hide the "part" field
fields.part.hidden = true;
if (fields.part) {
fields.part.hidden = true;
}
constructForm(`/api/company/part/${part}/`, {
fields: fields,
title: '{% trans "Edit Supplier Part" %}',
title: options.title || '{% trans "Edit Supplier Part" %}',
onSuccess: options.onSuccess
});
}
@ -952,6 +954,21 @@ function loadSupplierPartTable(table, url, options) {
title: '{% trans "Packaging" %}',
sortable: false,
},
{
field: 'available',
title: '{% trans "Available" %}',
sortable: true,
formatter: function(value, row) {
if (row.availability_updated) {
var html = formatDecimal(value);
var date = renderDate(row.availability_updated, {showTime: true});
html += `<span class='fas fa-info-circle float-right' title='{% trans "Last Updated" %}: ${date}'></span>`;
return html;
} else {
return '-';
}
}
},
{
field: 'actions',
title: '',

View File

@ -4,6 +4,7 @@
blankImage,
deleteButton,
editButton,
formatDecimal,
imageHoverIcon,
makeIconBadge,
makeIconButton,
@ -34,6 +35,13 @@ function deleteButton(url, text='{% trans "Delete" %}') {
}
/* Format a decimal (floating point) number, to strip trailing zeros
*/
function formatDecimal(number, places=5) {
return +parseFloat(number).toFixed(places);
}
function blankImage() {
return `/static/img/blank_image.png`;
}

View File

@ -1191,7 +1191,7 @@ function noResultBadge() {
function formatDate(row) {
// Function for formatting date field
var html = row.date;
var html = renderDate(row.date);
if (row.user_detail) {
html += `<span class='badge badge-right rounded-pill bg-secondary'>${row.user_detail.username}</span>`;
@ -1707,13 +1707,13 @@ function loadStockTable(table, options) {
val = '# ' + row.serial;
} else if (row.quantity != available) {
// Some quantity is available, show available *and* quantity
var ava = +parseFloat(available).toFixed(5);
var tot = +parseFloat(row.quantity).toFixed(5);
var ava = formatDecimal(available);
var tot = formatDecimal(row.quantity);
val = `${ava} / ${tot}`;
} else {
// Format floating point numbers with this one weird trick
val = +parseFloat(value).toFixed(5);
val = formatDecimal(value);
}
var html = renderLink(val, `/stock/item/${row.pk}/`);