2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-04 10:31:03 +00:00

Stock Tracking - Add Old Status to Deltas (#11179)

* match custom status tracking entry in edit

* add old_status to stockitemtracking

* test old_status tracking

* use vars for readability

* split custom status test

* move custom status from fixture to setup

* add old status to tracking table

* fallback to logical status if custom removed

* avoid shared deltas reference in loop

* track old status in stock add/remove/count/transfer

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
Jacob Felknor
2026-01-27 00:44:28 -07:00
committed by GitHub
parent 67c67a1650
commit df90934f0c
8 changed files with 224 additions and 22 deletions

View File

@@ -30,7 +30,8 @@ interface RenderStatusLabelOptionsInterface {
function renderStatusLabel(
key: string | number,
codes: StatusCodeListInterface,
options: RenderStatusLabelOptionsInterface = {}
options: RenderStatusLabelOptionsInterface = {},
fallback_key: string | number | null = null
) {
let text = null;
let color = null;
@@ -46,6 +47,19 @@ function renderStatusLabel(
}
}
if (!text && fallback_key !== null) {
// Handle fallback key (if provided)
for (const name in codes.values) {
const entry: StatusCodeInterface = codes.values[name];
if (entry?.key == fallback_key) {
text = entry.label;
color = entry.color;
break;
}
}
}
if (!text) {
console.error(
`ERR: renderStatusLabel could not find match for code ${key}`
@@ -164,11 +178,13 @@ export function getStatusCodeLabel(
export const StatusRenderer = ({
status,
type,
options
options,
fallbackStatus
}: {
status: string | number;
type: ModelType | string;
options?: RenderStatusLabelOptionsInterface;
fallbackStatus?: string | number | null;
}) => {
const statusCodes = getStatusCodes(type);
@@ -183,7 +199,7 @@ export const StatusRenderer = ({
return null;
}
return renderStatusLabel(status, statusCodes, options);
return renderStatusLabel(status, statusCodes, options, fallbackStatus);
};
/*

View File

@@ -283,7 +283,8 @@ function BuildOutputFormRow({
<Table.Td>{record.batch}</Table.Td>
<Table.Td>
<StatusRenderer
status={record.status}
status={record.custom_status_key || record.status}
fallbackStatus={record.status}
type={ModelType.stockitem}
/>{' '}
</Table.Td>

View File

@@ -646,7 +646,8 @@ function StockOperationsRow({
<Group grow justify='space-between' wrap='nowrap'>
<Text>{stockString}</Text>
<StatusRenderer
status={record.status_custom_key}
status={record.status_custom_key || record.status}
fallbackStatus={record.status}
type={ModelType.stockitem}
/>
</Group>

View File

@@ -956,6 +956,7 @@ export default function StockDetail() {
/>,
<StatusRenderer
status={stockitem.status_custom_key || stockitem.status}
fallbackStatus={stockitem.status}
type={ModelType.stockitem}
options={{
size: 'lg'

View File

@@ -66,7 +66,22 @@ export function StockTrackingTable({ itemId }: Readonly<{ itemId: number }>) {
key: 'status',
details:
deltas.status &&
StatusRenderer({ status: deltas.status, type: ModelType.stockitem })
StatusRenderer({
status: deltas.status,
type: ModelType.stockitem,
fallbackStatus: deltas.status_logical
})
},
{
label: t`Old Status`,
key: 'old_status',
details:
deltas.old_status &&
StatusRenderer({
status: deltas.old_status,
type: ModelType.stockitem,
fallbackStatus: deltas.old_status_logical
})
},
{
label: t`Quantity`,