2
0
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:
Oliver
2022-06-02 23:22:47 +10:00
committed by GitHub
parent 2074bf9156
commit 309ed595d7
7 changed files with 237 additions and 142 deletions

View File

@ -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;
},
},
);