mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Queryset annotation refactor (#3117)
* Refactor out 'ordering' serializer annotation field * Refactor BomItem serializer annotations * Factor out MPTT OuterRef query * Add 'available_stock' annotation to SalesOrderLineItem serializer - Allows for better rendering of stock availability in sales order table * Improve 'available quantity' rendering of salesorderlineitem table * Bump API version * Add docstring
This commit is contained in:
@ -3540,9 +3540,35 @@ function loadSalesOrderLineItemTable(table, options={}) {
|
||||
columns.push(
|
||||
{
|
||||
field: 'stock',
|
||||
title: '{% trans "In Stock" %}',
|
||||
title: '{% trans "Available Stock" %}',
|
||||
formatter: function(value, row) {
|
||||
return row.part_detail.stock;
|
||||
var available = row.available_stock;
|
||||
var total = row.part_detail.stock;
|
||||
var required = Math.max(row.quantity - row.allocated - row.shipped, 0);
|
||||
|
||||
var html = '';
|
||||
|
||||
if (total > 0) {
|
||||
var url = `/part/${row.part}/?display=part-stock`;
|
||||
|
||||
var text = available;
|
||||
|
||||
if (total != available) {
|
||||
text += ` / ${total}`;
|
||||
}
|
||||
|
||||
html = renderLink(text, url);
|
||||
} else {
|
||||
html += `<span class='badge rounded-pill bg-danger'>{% trans "No Stock Available" %}</span>`;
|
||||
}
|
||||
|
||||
if (available >= required) {
|
||||
html += `<span class='fas fa-check-circle icon-green float-right' title='{% trans "Sufficient stock available" %}'></span>`;
|
||||
} else {
|
||||
html += `<span class='fas fa-times-circle icon-red float-right' title='{% trans "Insufficient stock available" %}'></span>`;
|
||||
}
|
||||
|
||||
return html;
|
||||
},
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user