mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Implement a generic API endpoint for enumeration of status codes (#4543)
* Implement a generic API endpoint for enumeration of status codes * Adds endpoint for PurchaseOrderStatus * Add more endpoints (sales order / return orer) * Add endpoints for StockStatus and StockTrackingCode * Support build status * Use the attribute name as the dict key * Refactored status codes in javascript - Now accessible by "name" (instead of integer key) - Will make javascript code much more readable * Bump API version
This commit is contained in:
@ -15,10 +15,51 @@
|
||||
stockStatusDisplay,
|
||||
*/
|
||||
|
||||
{% include "status_codes.html" with label='stock' options=StockStatus.list %}
|
||||
{% include "status_codes.html" with label='stockHistory' options=StockHistoryCode.list %}
|
||||
{% include "status_codes.html" with label='build' options=BuildStatus.list %}
|
||||
{% include "status_codes.html" with label='purchaseOrder' options=PurchaseOrderStatus.list %}
|
||||
{% include "status_codes.html" with label='salesOrder' options=SalesOrderStatus.list %}
|
||||
{% include "status_codes.html" with label='returnOrder' options=ReturnOrderStatus.list %}
|
||||
{% include "status_codes.html" with label='returnOrderLineItem' options=ReturnOrderLineStatus.list %}
|
||||
|
||||
/*
|
||||
* Generic function to render a status label
|
||||
*/
|
||||
function renderStatusLabel(key, codes, options={}) {
|
||||
|
||||
let text = null;
|
||||
let label = null;
|
||||
|
||||
// Find the entry which matches the provided key
|
||||
for (var name in codes) {
|
||||
let entry = codes[name];
|
||||
|
||||
if (entry.key == key) {
|
||||
text = entry.value;
|
||||
label = entry.label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!text) {
|
||||
console.error(`renderStatusLabel could not find match for code ${key}`);
|
||||
}
|
||||
|
||||
// Fallback for color
|
||||
label = label || 'bg-dark';
|
||||
|
||||
if (!text) {
|
||||
text = key;
|
||||
}
|
||||
|
||||
let classes = `badge rounded-pill ${label}`;
|
||||
|
||||
if (options.classes) {
|
||||
classes += ` ${options.classes}`;
|
||||
}
|
||||
|
||||
return `<span class='${classes}'>${text}</span>`;
|
||||
}
|
||||
|
||||
|
||||
{% include "status_codes.html" with label='stock' data=StockStatus.list %}
|
||||
{% include "status_codes.html" with label='stockHistory' data=StockHistoryCode.list %}
|
||||
{% include "status_codes.html" with label='build' data=BuildStatus.list %}
|
||||
{% include "status_codes.html" with label='purchaseOrder' data=PurchaseOrderStatus.list %}
|
||||
{% include "status_codes.html" with label='salesOrder' data=SalesOrderStatus.list %}
|
||||
{% include "status_codes.html" with label='returnOrder' data=ReturnOrderStatus.list %}
|
||||
{% include "status_codes.html" with label='returnOrderLineItem' data=ReturnOrderLineStatus.list %}
|
||||
|
Reference in New Issue
Block a user