mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-17 05:34:37 +00:00
Implement stock adjust barcode actions (#13170)
This commit is contained in:
1 parent
c9ba1169f4
commit
c3948f56ed
7 files changed
+179
-57
No files matched your search
@@ -69,6 +69,12 @@ To access this page, select *Scan Barcode* from the main navigation menu:
|
||||
{{ image("barcode/barcode_nav_menu.png", "Barcode menu item") }}
|
||||
{{ image("barcode/barcode_scan_page.png", "Barcode scan page") }}
|
||||
|
||||
#### Stock Actions
|
||||
|
||||
If all of the selected items are [stock items](../stock/index.md), the *Stock Actions* menu provides access to the [stock adjustment](../stock/adjust.md) actions (such as counting, adding, removing or transferring stock). These actions are only available to users with the *change* permission for stock items.
|
||||
|
||||
Stock items cannot be deleted from the scan page. Other model types do not currently support any actions on the scan page.
|
||||
|
||||
## Barcodes in Forms
|
||||
|
||||
The InvenTree user interface supports direct scanning of barcodes within certain forms in the web UI. This means that any form field which points to a model which supports barcodes can accept barcode input. If barcode scanning is supported for a particular field, a barcode icon will be displayed next to the input field:
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
This file contains historical changelog information for the InvenTree UI components library.
|
||||
|
||||
### 1.6.0 - November 2026
|
||||
|
||||
Removes the `notYetImplemented` notification function, which is no longer used by the InvenTree user interface. Plugins which import this function must be updated.
|
||||
|
||||
### 1.5.0 - August 2026
|
||||
|
||||
Updated UI components library to match 1.5.0 InvenTree release.
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
|
||||
/**
|
||||
* Show a notification that the feature is not yet implemented
|
||||
*/
|
||||
export function notYetImplemented() {
|
||||
notifications.hide('not-implemented');
|
||||
|
||||
notifications.show({
|
||||
title: t`Not implemented`,
|
||||
message: t`This feature is not yet implemented`,
|
||||
color: 'red',
|
||||
id: 'not-implemented'
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notification that the user does not have permission to perform the action
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,6 @@ export {
|
||||
} from './functions/Navigation';
|
||||
|
||||
export {
|
||||
notYetImplemented,
|
||||
permissionDenied,
|
||||
invalidResponse,
|
||||
showTimeoutNotification
|
||||
|
||||
@@ -1118,14 +1118,11 @@ function useStockItems({
|
||||
items?: any[] | any;
|
||||
filters?: { [key: string]: any };
|
||||
}>) {
|
||||
// Only query the API if the items are not provided directly
|
||||
const query = useQuery({
|
||||
enabled: opened,
|
||||
enabled: opened && items === undefined,
|
||||
queryKey: ['stockItems', filters],
|
||||
queryFn: async () => {
|
||||
if (items !== undefined) {
|
||||
return Array.isArray(items) ? items : [items];
|
||||
}
|
||||
|
||||
if (!opened) {
|
||||
return [];
|
||||
}
|
||||
@@ -1151,8 +1148,12 @@ function useStockItems({
|
||||
return [];
|
||||
}
|
||||
|
||||
if (items !== undefined) {
|
||||
return Array.isArray(items) ? items : [items];
|
||||
}
|
||||
|
||||
return query.data ?? [];
|
||||
}, [opened, query.data]);
|
||||
}, [opened, items, query.data]);
|
||||
}
|
||||
|
||||
function ReturnStockMoveButton({
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { Trans } from '@lingui/react/macro';
|
||||
import {
|
||||
ActionIcon,
|
||||
Alert,
|
||||
Divider,
|
||||
Grid,
|
||||
@@ -12,19 +11,15 @@ import {
|
||||
Text
|
||||
} from '@mantine/core';
|
||||
import { randomId, useListState, useLocalStorage } from '@mantine/hooks';
|
||||
import {
|
||||
IconAlertCircle,
|
||||
IconNumber,
|
||||
IconQuestionMark
|
||||
} from '@tabler/icons-react';
|
||||
import { IconAlertCircle, IconQuestionMark } from '@tabler/icons-react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { StylishText } from '@lib/components/StylishText';
|
||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||
import { ModelInformationDict } from '@lib/enums/ModelInformation';
|
||||
import type { ModelType } from '@lib/enums/ModelType';
|
||||
import { ModelType } from '@lib/enums/ModelType';
|
||||
import { apiUrl } from '@lib/functions/Api';
|
||||
import { notYetImplemented } from '@lib/functions/Notification';
|
||||
import type { StockOperationProps } from '@lib/types/Forms';
|
||||
import { hideNotification, showNotification } from '@mantine/notifications';
|
||||
import dayjs from 'dayjs';
|
||||
import { api } from '../../App';
|
||||
@@ -32,6 +27,7 @@ import { BarcodeInput } from '../../components/barcodes/BarcodeInput';
|
||||
import type { BarcodeScanItem } from '../../components/barcodes/BarcodeScanItem';
|
||||
import PageTitle from '../../components/nav/PageTitle';
|
||||
import { showApiErrorMessage } from '../../functions/notifications';
|
||||
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
|
||||
import BarcodeScanTable from '../../tables/general/BarcodeScanTable';
|
||||
|
||||
export default function Scan() {
|
||||
@@ -46,6 +42,21 @@ export default function Scan() {
|
||||
|
||||
const [selection, setSelection] = useState<string[]>([]);
|
||||
|
||||
// Fetch the instance data for a given scan item
|
||||
const fetchInstanceData = useCallback(async (item: BarcodeScanItem) => {
|
||||
const model_info = ModelInformationDict[item.model!];
|
||||
|
||||
return api
|
||||
.get(apiUrl(model_info.api_endpoint, item.pk), {
|
||||
// Stock adjustment forms require location detail for each item
|
||||
params:
|
||||
item.model == ModelType.stockitem
|
||||
? { part_detail: true, location_detail: true }
|
||||
: undefined
|
||||
})
|
||||
.then((response) => response.data);
|
||||
}, []);
|
||||
|
||||
// Fetch model instance based on scan item
|
||||
const fetchInstance = useCallback(
|
||||
(item: BarcodeScanItem) => {
|
||||
@@ -66,12 +77,9 @@ export default function Scan() {
|
||||
return;
|
||||
}
|
||||
|
||||
const model_info = ModelInformationDict[item.model];
|
||||
|
||||
api
|
||||
.get(apiUrl(model_info.api_endpoint, item.pk))
|
||||
.then((response) => {
|
||||
item.instance = response.data;
|
||||
fetchInstanceData(item)
|
||||
.then((instance) => {
|
||||
item.instance = instance;
|
||||
historyHandlers.append(item);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -82,7 +90,7 @@ export default function Scan() {
|
||||
});
|
||||
});
|
||||
},
|
||||
[api, history]
|
||||
[fetchInstanceData, history]
|
||||
);
|
||||
|
||||
// Barcode scanning callback function
|
||||
@@ -149,46 +157,114 @@ export default function Scan() {
|
||||
return history.filter((item) => selection.includes(item.id));
|
||||
}, [selection, history]);
|
||||
|
||||
// Reload instance data for the selected items (e.g. after a stock adjustment)
|
||||
const refreshSelectedItems = useCallback(() => {
|
||||
const items = selectedItems.filter((item) => item.model && item.pk);
|
||||
|
||||
if (items.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Promise.all(
|
||||
items.map((item) =>
|
||||
fetchInstanceData(item)
|
||||
.then((instance) => ({ id: item.id, instance: instance }))
|
||||
.catch((error) => ({
|
||||
id: item.id,
|
||||
// The item no longer exists (e.g. it was merged into another item)
|
||||
missing: error?.response?.status == 404
|
||||
}))
|
||||
)
|
||||
).then((results) => {
|
||||
historyHandlers.apply((item) => {
|
||||
const result: any = results.find((r) => r.id == item.id);
|
||||
|
||||
if (result?.instance) {
|
||||
return { ...item, instance: result.instance };
|
||||
} else if (result?.missing) {
|
||||
return { ...item, instance: undefined };
|
||||
}
|
||||
|
||||
// Retain existing data if the item could not be reloaded
|
||||
return item;
|
||||
});
|
||||
});
|
||||
}, [fetchInstanceData, selectedItems]);
|
||||
|
||||
// Scan history may be stale, so reload instance data when the selection changes
|
||||
useEffect(() => {
|
||||
refreshSelectedItems();
|
||||
}, [selection]);
|
||||
|
||||
// The single model type shared by all selected items (if any)
|
||||
const selectedModelType: ModelType | undefined = useMemo(() => {
|
||||
const modelTypes = new Set(selectedItems.map((item) => item.model));
|
||||
|
||||
return modelTypes.size == 1 ? selectedItems[0]?.model : undefined;
|
||||
}, [selectedItems]);
|
||||
|
||||
const stockOperationProps: StockOperationProps = useMemo(() => {
|
||||
return {
|
||||
items:
|
||||
selectedModelType == ModelType.stockitem
|
||||
? selectedItems
|
||||
.map((item) => item.instance)
|
||||
.filter((instance) => !!instance)
|
||||
: [],
|
||||
refresh: refreshSelectedItems
|
||||
};
|
||||
}, [selectedModelType, selectedItems, refreshSelectedItems]);
|
||||
|
||||
const stockAdjustActions = useStockAdjustActions({
|
||||
formProps: stockOperationProps,
|
||||
enabled: selectedModelType == ModelType.stockitem,
|
||||
delete: false
|
||||
});
|
||||
|
||||
// selected actions component
|
||||
const SelectedActions = useMemo(() => {
|
||||
const uniqueObjectTypes = new Set(selectedItems.map((item) => item.model));
|
||||
|
||||
if (uniqueObjectTypes.size === 0) {
|
||||
return (
|
||||
<Group gap={0}>
|
||||
<IconQuestionMark color='orange' />
|
||||
<Trans>Selected elements are not known</Trans>
|
||||
</Group>
|
||||
);
|
||||
} else if (uniqueObjectTypes.size > 1) {
|
||||
if (uniqueObjectTypes.size > 1) {
|
||||
return (
|
||||
<Group gap={0}>
|
||||
<IconAlertCircle color='orange' />
|
||||
<Trans>Multiple object types selected</Trans>
|
||||
</Group>
|
||||
);
|
||||
} else if (!selectedModelType) {
|
||||
return (
|
||||
<Group gap={0}>
|
||||
<IconQuestionMark color='orange' />
|
||||
<Trans>Selected elements are not known</Trans>
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
selectedModelType != ModelType.stockitem ||
|
||||
!stockAdjustActions.hasActions
|
||||
) {
|
||||
return (
|
||||
<Text fz='sm' c='dimmed'>
|
||||
<Trans>No actions available for the selected items</Trans>
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Group justify='space-between'>
|
||||
<Text fz='sm' c='dimmed'>
|
||||
<Trans>Actions ... </Trans>
|
||||
<Trans>Stock Actions</Trans>
|
||||
</Text>
|
||||
<Group>
|
||||
<ActionIcon
|
||||
onClick={notYetImplemented}
|
||||
title={t`Count`}
|
||||
variant='default'
|
||||
>
|
||||
<IconNumber />
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
</>
|
||||
{stockAdjustActions.dropdown}
|
||||
</Group>
|
||||
);
|
||||
}, [selectedItems]);
|
||||
}, [selectedItems, selectedModelType, stockAdjustActions]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{stockAdjustActions.modals.map((modal) => modal.modal)}
|
||||
<PageTitle title={t`Barcode Scanning`} />
|
||||
<Group justify='space-between'>
|
||||
<Group justify='left'>
|
||||
|
||||
@@ -74,6 +74,56 @@ test('Barcode Scanning - Stockitem', async ({ browser }) => {
|
||||
await page.getByRole('cell', { name: 'Quantity: 100' }).waitFor();
|
||||
});
|
||||
|
||||
test('Barcode Scanning - Stock Actions', async ({ browser }) => {
|
||||
// Create a new stock item, so that other tests are not affected
|
||||
const api = await createApi({});
|
||||
|
||||
const stockItem = await api
|
||||
.post('stock/', {
|
||||
data: { part: 1, quantity: 25, location: 3 }
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => data[0]);
|
||||
|
||||
await api.dispose();
|
||||
|
||||
const page = await doCachedLogin(browser, { url: 'scan/' });
|
||||
|
||||
// Nothing selected - no actions are available
|
||||
await page.getByText('Scan and select items to perform actions').waitFor();
|
||||
|
||||
// Scan a non-stock item - no stock actions are available
|
||||
await scan(page, '{"part": 1}');
|
||||
await page.getByRole('cell', { name: 'part', exact: true }).waitFor();
|
||||
await page
|
||||
.getByRole('row', { name: /R_10R_0402_1%/ })
|
||||
.getByLabel('Select record')
|
||||
.check();
|
||||
await page.getByText('No actions available for the selected items').waitFor();
|
||||
await page
|
||||
.getByRole('row', { name: /R_10R_0402_1%/ })
|
||||
.getByLabel('Select record')
|
||||
.uncheck();
|
||||
|
||||
// Scan the new stock item
|
||||
await scan(page, `{"stockitem": ${stockItem.pk}}`);
|
||||
await page.getByRole('cell', { name: 'Quantity: 25' }).waitFor();
|
||||
|
||||
const stockRow = page.getByRole('row', { name: /Quantity: 25/ });
|
||||
await stockRow.getByLabel('Select record').check();
|
||||
|
||||
// Count the selected stock item
|
||||
await page.getByLabel('action-menu-stock-actions').click();
|
||||
await page.getByLabel('action-menu-stock-actions-count-stock').click();
|
||||
await page.getByText('Count the selected stock items').waitFor();
|
||||
await page.getByLabel('number-field-quantity').fill('17');
|
||||
await page.getByRole('button', { name: 'Submit' }).click();
|
||||
await page.getByText('Stock counted').waitFor();
|
||||
|
||||
// The scanned item is reloaded with the new quantity
|
||||
await page.getByRole('cell', { name: 'Quantity: 17' }).waitFor();
|
||||
});
|
||||
|
||||
test('Barcode Scanning - StockLocation', async ({ browser }) => {
|
||||
const page = await doCachedLogin(browser, { url: 'scan/' });
|
||||
|
||||
|
||||
Reference in new issue
Block a user