Merge remote-tracking branch 'inventree/master' into bom-serializer-quantity

This commit is contained in:
Oliver Walters 2022-04-05 19:49:06 +10:00
commit e0acfe492b
5 changed files with 46 additions and 36 deletions

View File

@ -1348,6 +1348,7 @@ class PartList(generics.ListCreateAPIView):
'creation_date',
'IPN',
'in_stock',
'unallocated_stock',
'category',
]

View File

@ -1746,7 +1746,7 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
required: true,
render_part_detail: true,
render_location_detail: true,
render_stock_id: false,
render_pk: false,
auto_fill: true,
auto_fill_filters: auto_fill_filters,
onSelect: function(data, field, opts) {

View File

@ -31,6 +31,24 @@
*/
// Should the ID be rendered for this string
function renderId(title, pk, parameters={}) {
// Default = true
var render = true;
if ('render_pk' in parameters) {
render = parameters['render_pk'];
}
if (render) {
return `<span class='float-right'><small>${title}: ${pk}</small></span>`;
} else {
return '';
}
}
// Renderer for "Company" model
// eslint-disable-next-line no-unused-vars
function renderCompany(name, data, parameters={}, options={}) {
@ -39,7 +57,7 @@ function renderCompany(name, data, parameters={}, options={}) {
html += `<span><b>${data.name}</b></span> - <i>${data.description}</i>`;
html += `<span class='float-right'><small>{% trans "Company ID" %}: ${data.pk}</small></span>`;
html += renderId('{% trans "Company ID" %}', data.pk, parameters);
return html;
}
@ -67,18 +85,6 @@ function renderStockItem(name, data, parameters={}, options={}) {
part_detail = `<img src='${image}' class='select2-thumbnail'><span>${data.part_detail.full_name}</span> - `;
}
var render_stock_id = true;
if ('render_stock_id' in parameters) {
render_stock_id = parameters['render_stock_id'];
}
var stock_id = '';
if (render_stock_id) {
stock_id = `<span class='float-right'><small>{% trans "Stock ID" %}: ${data.pk}</small></span>`;
}
var render_location_detail = false;
if ('render_location_detail' in parameters) {
@ -88,7 +94,7 @@ function renderStockItem(name, data, parameters={}, options={}) {
var location_detail = '';
if (render_location_detail && data.location_detail) {
location_detail = ` - (<em>${data.location_detail.name}</em>)`;
location_detail = ` <small>- (<em>${data.location_detail.name}</em>)</small>`;
}
var stock_detail = '';
@ -103,7 +109,10 @@ function renderStockItem(name, data, parameters={}, options={}) {
var html = `
<span>
${part_detail}${stock_detail}${location_detail}${stock_id}
${part_detail}
${stock_detail}
${location_detail}
${renderId('{% trans "Stock ID" %}', data.pk, parameters)}
</span>
`;
@ -183,7 +192,7 @@ function renderPart(name, data, parameters={}, options={}) {
<small>
${stock_data}
${extra}
{% trans "Part ID" %}: ${data.pk}
${renderId('{% trans "Part ID" $}', data.pk, parameters)}
</small>
</span>`;
@ -245,13 +254,7 @@ function renderPurchaseOrder(name, data, parameters={}, options={}) {
html += ` - <em>${data.description}</em>`;
}
html += `
<span class='float-right'>
<small>
{% trans "Order ID" %}: ${data.pk}
</small>
</span>
`;
html += renderId('{% trans "Order ID" %}', data.pk, parameters);
return html;
}
@ -277,12 +280,7 @@ function renderSalesOrder(name, data, parameters={}, options={}) {
html += ` - <em>${data.description}</em>`;
}
html += `
<span class='float-right'>
<small>
{% trans "Order ID" %}: ${data.pk}
</small>
</span>`;
html += renderId('{% trans "Order ID" %}', data.pk, parameters);
return html;
}

View File

@ -491,13 +491,16 @@ function duplicateBom(part_id, options={}) {
}
/*
* Construct a "badge" label showing stock information for this particular part
*/
function partStockLabel(part, options={}) {
if (part.in_stock) {
// There IS stock available for this part
// Is stock "low" (below the 'minimum_stock' quantity)?
if (part.minimum_stock && 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>`;
} else if (part.unallocated_stock == 0) {
if (part.ordering) {
@ -507,11 +510,15 @@ function partStockLabel(part, options={}) {
// 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>`;
} else {
// There is no available stock
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "Available" %}: 0/${part.in_stock}${part.units}</span>`;
// There is no available stock at all
return `<span class='badge rounded-pill bg-warning ${options.classes}'>{% trans "No stock available" %}</span>`;
}
} else {
} 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>`;
} else {
// Stock is completely available
return `<span class='badge rounded-pill bg-success ${options.classes}'>{% trans "Available" %}: ${part.unallocated_stock}${part.units}</span>`;
}
} else {
// There IS NO stock available for this part
@ -1355,7 +1362,7 @@ function loadPartTable(table, url, options={}) {
col = {
field: 'unallocated_stock',
title: '{% trans "Available" %}',
title: '{% trans "Stock" %}',
searchable: false,
formatter: function(value, row) {
var link = '?display=part-stock';
@ -1377,7 +1384,7 @@ function loadPartTable(table, url, options={}) {
link = '?display=build-orders';
} else {
// There is no available stock
value = `0<span class='badge badge-right rounded-pill bg-warning'>{% trans "Not available" %}</span>`;
value = `0<span class='badge badge-right rounded-pill bg-warning'>{% trans "No stock available" %}</span>`;
}
}
} else {

View File

@ -132,6 +132,7 @@ function updateSearch() {
renderStockItem,
{
url: '/stock/item',
render_location_detail: true,
}
);
}
@ -232,6 +233,9 @@ function addSearchQuery(key, title, query_url, query_params, render_func, render
query_params.offset = 0;
query_params.limit = user_settings.SEARCH_PREVIEW_RESULTS;
// Do not display "pk" value for search results
render_params.render_pk = false;
// Add the result group to the panel
$('#offcanvas-search').find('#search-results').append(`
<div class='search-result-group-wrapper' id='search-results-wrapper-${key}'></div>