2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 05:00:58 +00:00

Barcode scanning (#8732)

* Implement new "general purpose" barcode scan dialog

- Separated widgets for camera / keyboard / wedge scanner
- UI / UX improvements

* Handle scan results

* Fix missing imports

* Handle successful global scan

* Handle error when linking barcode

* Backend fix for InvenTreeInternalBarcodePlugin

* Error handling

* Working on scanner input

* Refactor scan page

* Callback from scanner input

* Refactoring <Scan> page

* Allow InvenTreeTable to be used with supplied data

* Refactor optionalparams

* Refactoring table of scan results

* Implement callbacks

* Navigate from barcode table

* Fix delete callback

* Refactor callbacks

* Refactor idAccessor

- Access as part of useTable hook
- No longer hard-coded to 'pk'

* prevent duplicate scans

* Fix for deleting items from table

* Cleanup

* Bump API version

* Adjust playwright tests

* Update playwright tests

* Update barcode screenshots

* Fix links

* Add quick links to barcode formats

* Updated screenshots

* Fix for BuildLineSubTable

* Specify idAccessor values

* Clear barcode input after timeout period

* Move items

* Fix for playwright test

* Remove debug print

* Additional error ignores

* Cleanup scanner input

- Simplify
- Prevent errant keycodes from closing the scanner dialog

* Playwright test adjustments
This commit is contained in:
Oliver
2024-12-28 20:38:53 +11:00
committed by GitHub
parent 0765b00520
commit 3e73162368
50 changed files with 1204 additions and 1141 deletions

View File

@ -74,6 +74,7 @@ export const test = baseTest.extend({
url != 'http://localhost:8000/api/barcode/' &&
url != 'https://docs.inventree.org/en/versions.json' &&
url != 'http://localhost:5173/favicon.ico' &&
!url.startsWith('https://api.github.com/repos/inventree') &&
!url.startsWith('http://localhost:8000/api/news/') &&
!url.startsWith('http://localhost:8000/api/notifications/') &&
!url.startsWith('chrome://') &&

View File

@ -1,7 +1,7 @@
import { test } from './baseFixtures.js';
import { doQuickLogin } from './login.js';
test('Modals as admin', async ({ page }) => {
test('Modals - Admin', async ({ page }) => {
await doQuickLogin(page, 'admin', 'inventree');
// use server info
@ -49,15 +49,4 @@ test('Modals as admin', async ({ page }) => {
.getByRole('button', { name: 'About InvenTree About the InvenTree org' })
.click();
await page.getByRole('cell', { name: 'InvenTree Version' }).click();
await page.goto('./platform/');
// Barcode scanning window
await page.getByRole('button', { name: 'Open Barcode Scanner' }).click();
await page.getByRole('banner').getByRole('button').click();
await page.getByRole('button', { name: 'Open Barcode Scanner' }).click();
await page.getByRole('button', { name: 'Close modal' }).click();
await page.getByRole('button', { name: 'Open Barcode Scanner' }).click();
await page.waitForTimeout(500);
await page.getByRole('banner').getByRole('button').click();
});

View File

@ -268,6 +268,4 @@ test('Build Order - Filters', async ({ page }) => {
await openFilterDrawer(page);
await clickButtonIfVisible(page, 'Clear Filters');
await page.waitForTimeout(2500);
});

View File

@ -3,6 +3,70 @@ import { baseUrl } from '../defaults.ts';
import { clickButtonIfVisible, openFilterDrawer } from '../helpers.ts';
import { doQuickLogin } from '../login.ts';
test('Purchase Orders', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/home`);
await page.getByRole('tab', { name: 'Purchasing' }).click();
await page.getByRole('tab', { name: 'Purchase Orders' }).click();
// Check for expected values
await page.getByRole('cell', { name: 'PO0014' }).waitFor();
await page.getByText('Wire-E-Coyote').waitFor();
await page.getByText('Cancelled').first().waitFor();
await page.getByText('Pending').first().waitFor();
await page.getByText('On Hold').first().waitFor();
// Click through to a particular purchase order
await page.getByRole('cell', { name: 'PO0013' }).click();
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
});
test('Purchase Orders - Barcodes', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/purchasing/purchase-order/13/detail`);
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
// Display QR code
await page.getByLabel('action-menu-barcode-actions').click();
await page.getByLabel('action-menu-barcode-actions-view').click();
await page.getByRole('img', { name: 'QR Code' }).waitFor();
await page.getByRole('banner').getByRole('button').click();
// Link to barcode
await page.getByLabel('action-menu-barcode-actions').click();
await page.getByLabel('action-menu-barcode-actions-link-barcode').click();
await page.getByLabel('barcode-input-scanner').click();
// Simulate barcode scan
await page.getByPlaceholder('Enter barcode data').fill('1234567890');
await page.getByRole('button', { name: 'Scan', exact: true }).click();
await page.waitForTimeout(250);
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
// Ensure we can scan back to this page, with the associated barcode
await page.goto(`${baseUrl}/home`);
await page.waitForTimeout(250);
await page.getByRole('button', { name: 'Open Barcode Scanner' }).click();
await page.getByPlaceholder('Enter barcode data').fill('1234567890');
await page.getByRole('button', { name: 'Scan', exact: true }).click();
await page.getByText('Purchase Order: PO0013', { exact: true }).waitFor();
// Unlink barcode
await page.getByLabel('action-menu-barcode-actions').click();
await page.getByLabel('action-menu-barcode-actions-unlink-barcode').click();
await page.getByRole('heading', { name: 'Unlink Barcode' }).waitFor();
await page.getByText('This will remove the link to').waitFor();
await page.getByRole('button', { name: 'Unlink Barcode' }).click();
await page.waitForTimeout(250);
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
});
test('Purchase Orders - General', async ({ page }) => {
await doQuickLogin(page);

View File

@ -3,6 +3,57 @@ import { baseUrl } from '../defaults.ts';
import { clearTableFilters, setTableChoiceFilter } from '../helpers.ts';
import { doQuickLogin } from '../login.ts';
test('Sales Orders - Tabs', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/sales/index/`);
await page.waitForURL('**/platform/sales/**');
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.waitForURL('**/platform/sales/index/salesorders');
await page.getByRole('tab', { name: 'Return Orders' }).click();
// Customers
await page.getByRole('tab', { name: 'Customers' }).click();
await page.getByText('Customer A').click();
await page.getByRole('tab', { name: 'Notes' }).click();
await page.getByRole('tab', { name: 'Attachments' }).click();
await page.getByRole('tab', { name: 'Contacts' }).click();
await page.getByRole('tab', { name: 'Assigned Stock' }).click();
await page.getByRole('tab', { name: 'Return Orders' }).click();
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.getByRole('tab', { name: 'Contacts' }).click();
await page.getByRole('cell', { name: 'Dorathy Gross' }).waitFor();
await page
.getByRole('row', { name: 'Dorathy Gross dorathy.gross@customer.com' })
.waitFor();
// Sales Order Details
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.getByRole('cell', { name: 'SO0001' }).click();
await page
.getByLabel('Order Details')
.getByText('Selling some stuff')
.waitFor();
await page.getByRole('tab', { name: 'Line Items' }).click();
await page.getByRole('tab', { name: 'Shipments' }).click();
await page.getByRole('tab', { name: 'Build Orders' }).click();
await page.getByText('No records found').first().waitFor();
await page.getByRole('tab', { name: 'Attachments' }).click();
await page.getByText('No attachments found').first().waitFor();
await page.getByRole('tab', { name: 'Notes' }).click();
await page.getByRole('tab', { name: 'Order Details' }).click();
// Return Order Details
await page.getByRole('link', { name: 'Customer A' }).click();
await page.getByRole('tab', { name: 'Return Orders' }).click();
await page.getByRole('cell', { name: 'RMA-' }).click();
await page.getByText('RMA-0001', { exact: true }).waitFor();
await page.getByRole('tab', { name: 'Line Items' }).click();
await page.getByRole('tab', { name: 'Attachments' }).click();
await page.getByRole('tab', { name: 'Notes' }).click();
});
test('Sales Orders - Basic Tests', async ({ page }) => {
await doQuickLogin(page);
@ -129,55 +180,3 @@ test('Sales Orders - Shipments', async ({ page }) => {
await page.getByText('Quantity: 42').click();
await page.getByRole('button', { name: 'Cancel' }).click();
});
test('Purchase Orders', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/home`);
await page.getByRole('tab', { name: 'Purchasing' }).click();
await page.getByRole('tab', { name: 'Purchase Orders' }).click();
// Check for expected values
await page.getByRole('cell', { name: 'PO0014' }).waitFor();
await page.getByText('Wire-E-Coyote').waitFor();
await page.getByText('Cancelled').first().waitFor();
await page.getByText('Pending').first().waitFor();
await page.getByText('On Hold').first().waitFor();
// Click through to a particular purchase order
await page.getByRole('cell', { name: 'PO0013' }).click();
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
});
test('Purchase Orders - Barcodes', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/purchasing/purchase-order/13/detail`);
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
// Display QR code
await page.getByLabel('action-menu-barcode-actions').click();
await page.getByLabel('action-menu-barcode-actions-view').click();
await page.getByRole('img', { name: 'QR Code' }).waitFor();
await page.getByRole('banner').getByRole('button').click();
// Link to barcode
await page.getByLabel('action-menu-barcode-actions').click();
await page.getByLabel('action-menu-barcode-actions-link-barcode').click();
await page.getByRole('heading', { name: 'Link Barcode' }).waitFor();
await page
.getByPlaceholder('Scan barcode data here using')
.fill('1234567890');
await page.getByRole('button', { name: 'Link' }).click();
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
// Unlink barcode
await page.getByLabel('action-menu-barcode-actions').click();
await page.getByLabel('action-menu-barcode-actions-unlink-barcode').click();
await page.getByRole('heading', { name: 'Unlink Barcode' }).waitFor();
await page.getByText('This will remove the link to').waitFor();
await page.getByRole('button', { name: 'Unlink Barcode' }).click();
await page.waitForTimeout(500);
await page.getByRole('button', { name: 'Issue Order' }).waitFor();
});

View File

@ -2,157 +2,120 @@ import { test } from '../baseFixtures';
import { baseUrl } from '../defaults';
import { doQuickLogin } from '../login';
async function defaultScanTest(page, search_text) {
const scan = async (page, barcode) => {
await page.getByLabel('barcode-input-scanner').click();
await page.getByLabel('barcode-scan-keyboard-input').fill(barcode);
await page.getByRole('button', { name: 'Scan', exact: true }).click();
};
test('Scanning - Dialog', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan`);
await page.getByPlaceholder('Select input method').click();
await page.getByRole('option', { name: 'Manual input' }).click();
await page.getByPlaceholder('Enter item serial or data').click();
await page.getByRole('button', { name: 'Open Barcode Scanner' }).click();
await scan(page, '{"part": 15}');
// nonsense data
await page.getByPlaceholder('Enter item serial or data').fill('123');
await page.getByPlaceholder('Enter item serial or data').press('Enter');
await page.getByRole('cell', { name: '123' }).click();
await page.getByRole('cell', { name: 'manually' }).click();
await page.getByRole('button', { name: 'Lookup part' }).click();
await page.getByRole('button', { name: 'Delete', exact: true }).click();
await page.getByText('Part: R_550R_0805_1%', { exact: true }).waitFor();
await page.getByText('Available:').waitFor();
await page.getByText('Required:').waitFor();
});
await page.getByPlaceholder('Enter item serial or data').fill(search_text);
await page.getByPlaceholder('Enter item serial or data').press('Enter');
await page.getByRole('checkbox').nth(2).check();
await page.getByRole('button', { name: 'Lookup part' }).click();
}
test('Scanning', async ({ page }) => {
test('Scanning - Basic', async ({ page }) => {
await doQuickLogin(page);
await page.getByLabel('navigation-menu').click();
await page.getByRole('button', { name: 'System Information' }).click();
await page.locator('button').filter({ hasText: 'Close' }).click();
// Navigate to the 'scan' page
await page.getByLabel('navigation-menu').click();
await page.getByRole('button', { name: 'Scan Barcode' }).click();
await page.getByPlaceholder('Select input method').click();
await page.getByRole('option', { name: 'Manual input' }).click();
await page.getByPlaceholder('Enter item serial or data').click();
await page.getByPlaceholder('Enter item serial or data').fill('123');
await page.getByPlaceholder('Enter item serial or data').press('Enter');
await page.getByRole('cell', { name: 'manually' }).click();
await page.getByRole('button', { name: 'Lookup part' }).click();
await page.getByPlaceholder('Select input method').click();
await page.getByRole('option', { name: 'Manual input' }).click();
await page.getByText('Scan or enter barcode data').waitFor();
// Select the scanner input
await page.getByLabel('barcode-input-scanner').click();
await page.getByPlaceholder('Enter barcode data').fill('123-abc');
await page.getByRole('button', { name: 'Scan', exact: true }).click();
// Select the camera input
await page.getByLabel('barcode-input-camera').click();
await page.getByText('Start scanning by selecting a camera').waitFor();
await page.getByText('No match found for barcode').waitFor();
});
test('Scanning (Part)', async ({ page }) => {
await defaultScanTest(page, '{"part": 1}');
test('Scanning - Part', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"part": 1}');
// part: 1
await page.getByText('R_10R_0402_1%').waitFor();
await page.getByText('Stock:').waitFor();
await page.getByRole('cell', { name: 'part' }).waitFor();
await page.getByRole('cell', { name: 'part', exact: true }).waitFor();
});
test('Scanning (Stockitem)', async ({ page }) => {
// TODO: Come back to here and re-enable this test
// TODO: Something is wrong with the test, it's not working as expected
// TODO: The barcode scanning page needs some attention in general
/*
* TODO: 2024-11-08 : https://github.com/inventree/InvenTree/pull/8445
await defaultScanTest(page, '{"stockitem": 408}');
test('Scanning - Stockitem', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"stockitem": 408}');
// stockitem: 408
await page.getByText('1551ABK').waitFor();
await page.getByText('Quantity: 100').waitFor();
await page.getByRole('cell', { name: 'Quantity: 100' }).waitFor();
*/
});
test('Scanning (StockLocation)', async ({ page }) => {
await defaultScanTest(page, '{"stocklocation": 3}');
test('Scanning - StockLocation', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"stocklocation": 3}');
// stocklocation: 3
await page.getByText('Factory/Storage Room B', { exact: true }).waitFor();
await page.getByText('Storage Room B (green door)').waitFor();
await page.getByRole('cell', { name: 'stocklocation' }).waitFor();
await page
.getByRole('cell', { name: 'stocklocation', exact: true })
.waitFor();
});
test('Scanning (SupplierPart)', async ({ page }) => {
await defaultScanTest(page, '{"supplierpart": 204}');
test('Scanning - SupplierPart', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"supplierpart": 204}');
// supplierpart: 204
await page.waitForTimeout(1000);
await page.getByText('1551ABK').first().waitFor();
await page.getByRole('cell', { name: 'supplierpart' }).waitFor();
await page.getByRole('cell', { name: 'supplierpart', exact: true }).waitFor();
});
test('Scanning (PurchaseOrder)', async ({ page }) => {
await defaultScanTest(page, '{"purchaseorder": 12}');
test('Scanning - PurchaseOrder', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"purchaseorder": 12}');
// purchaseorder: 12
await page.getByText('PO0012').waitFor();
await page.getByText('Wire from Wirey').waitFor();
await page.getByRole('cell', { name: 'purchaseorder' }).waitFor();
await page
.getByRole('cell', { name: 'purchaseorder', exact: true })
.waitFor();
});
test('Scanning (SalesOrder)', async ({ page }) => {
await defaultScanTest(page, '{"salesorder": 6}');
test('Scanning - SalesOrder', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"salesorder": 6}');
// salesorder: 6
await page.getByText('SO0006').waitFor();
await page.getByText('Selling more stuff to this').waitFor();
await page.getByRole('cell', { name: 'salesorder' }).waitFor();
await page.getByRole('cell', { name: 'salesorder', exact: true }).waitFor();
});
test('Scanning (Build)', async ({ page }) => {
await defaultScanTest(page, '{"build": 8}');
test('Scanning - Build', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/scan/`);
await scan(page, '{"build": 8}');
// build: 8
await page.getByText('BO0008').waitFor();
await page.getByText('PCBA build').waitFor();
await page.getByRole('cell', { name: 'build', exact: true }).waitFor();
});
test('Scanning (General)', async ({ page }) => {
await defaultScanTest(page, '{"unknown": 312}');
await page.getByText('"unknown": 312').waitFor();
// checkAll
await page.getByRole('checkbox').nth(0).check();
// Delete
await page.getByRole('button', { name: 'Delete', exact: true }).click();
// Reload to check history is working
await page.goto(`${baseUrl}/scan`);
await page.getByText('"unknown": 312').waitFor();
// Clear history
await page.getByRole('button', { name: 'Delete History' }).click();
await page.getByText('No history').waitFor();
// reload again
await page.goto(`${baseUrl}/scan`);
await page.getByText('No history').waitFor();
// Empty dummy input
await page.getByPlaceholder('Enter item serial or data').fill('');
await page.getByPlaceholder('Enter item serial or data').press('Enter');
// Empty add dummy item
await page.getByRole('button', { name: 'Add dummy item' }).click();
// Empty plus sign
await page
.locator('div')
.filter({ hasText: /^InputAdd dummy item$/ })
.getByRole('button')
.first()
.click();
// Toggle fullscreen
await page.getByRole('button', { name: 'Toggle Fullscreen' }).click();
await page.waitForTimeout(1000);
await page.getByRole('button', { name: 'Toggle Fullscreen' }).click();
});

View File

@ -206,8 +206,6 @@ test('Stock - Stock Actions', async ({ page }) => {
await page.getByText('Unavailable').waitFor();
await page.getByLabel('action-menu-stock-operations').click();
await page.getByLabel('action-menu-stock-operations-return').click();
await page.waitForTimeout(2500);
});
test('Stock - Tracking', async ({ page }) => {

View File

@ -2,57 +2,6 @@ import { test } from './baseFixtures.js';
import { baseUrl } from './defaults.js';
import { doQuickLogin } from './login.js';
test('Sales', async ({ page }) => {
await doQuickLogin(page);
await page.goto(`${baseUrl}/sales/index/`);
await page.waitForURL('**/platform/sales/**');
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.waitForURL('**/platform/sales/index/salesorders');
await page.getByRole('tab', { name: 'Return Orders' }).click();
// Customers
await page.getByRole('tab', { name: 'Customers' }).click();
await page.getByText('Customer A').click();
await page.getByRole('tab', { name: 'Notes' }).click();
await page.getByRole('tab', { name: 'Attachments' }).click();
await page.getByRole('tab', { name: 'Contacts' }).click();
await page.getByRole('tab', { name: 'Assigned Stock' }).click();
await page.getByRole('tab', { name: 'Return Orders' }).click();
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.getByRole('tab', { name: 'Contacts' }).click();
await page.getByRole('cell', { name: 'Dorathy Gross' }).waitFor();
await page
.getByRole('row', { name: 'Dorathy Gross dorathy.gross@customer.com' })
.waitFor();
// Sales Order Details
await page.getByRole('tab', { name: 'Sales Orders' }).click();
await page.getByRole('cell', { name: 'SO0001' }).click();
await page
.getByLabel('Order Details')
.getByText('Selling some stuff')
.waitFor();
await page.getByRole('tab', { name: 'Line Items' }).click();
await page.getByRole('tab', { name: 'Shipments' }).click();
await page.getByRole('tab', { name: 'Build Orders' }).click();
await page.getByText('No records found').first().waitFor();
await page.getByRole('tab', { name: 'Attachments' }).click();
await page.getByText('No attachments found').first().waitFor();
await page.getByRole('tab', { name: 'Notes' }).click();
await page.getByRole('tab', { name: 'Order Details' }).click();
// Return Order Details
await page.getByRole('link', { name: 'Customer A' }).click();
await page.getByRole('tab', { name: 'Return Orders' }).click();
await page.getByRole('cell', { name: 'RMA-' }).click();
await page.getByText('RMA-0001', { exact: true }).waitFor();
await page.getByRole('tab', { name: 'Line Items' }).click();
await page.getByRole('tab', { name: 'Attachments' }).click();
await page.getByRole('tab', { name: 'Notes' }).click();
});
test('Company', async ({ page }) => {
await doQuickLogin(page);

View File

@ -92,8 +92,6 @@ test('Login - Failures', async ({ page }) => {
await page.getByLabel('login-password').fill('');
await loginWithError();
await page.waitForTimeout(2500);
});
test('Login - Change Password', async ({ page }) => {

View File

@ -122,7 +122,4 @@ test('Plugins - Locate Item', async ({ page, request }) => {
await page.getByLabel('action-button-locate-item').click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('Item location requested').waitFor();
await page.waitForTimeout(2500);
return;
});