mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Barcode logging (#8150)
* Add model for recording barcode scan results * Add "admin" interface for new model * Add API endpoints for barcode scan history * Add global setting to control barcode result save * Add frontend API endpoint * Add PUI table in "admin center" * Add API filter class * Enable table filtering * Update model definition * Allow more characters for barcode log * Log results to server * Add setting to control how long results are stored * Table updates * Add background task to delete old barcode scans * Add detail drawer for barcode scan * Log messages for BarcodePOReceive * Add warning message if barcode logging is not enabled * Add "context" data to BarcodeScanResult * Display context data (if available) * Add context data when scanning * Simplify / refactor BarcodeSOAllocate * Refactor BarcodePOAllocate * Limit the number of saved scans * Improve error message display in PUI * Simplify barcode logging * Improve table * Updates * Settings page fix * Fix panel tooltips * Adjust table * Add "result" field * Refactor calls to "log_scan" * Display result in PUI table * Updates * Fix typo * Update unit test * Improve exception handling * Unit test updates * Enhanced unit test * Ensure all database key config values are upper case * Refactor some playwright helpers * Adds playwright test for barcode scan history table * Requires some timeout * Add docs
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| export const classicUrl = 'http://127.0.0.1:8000'; | ||||
|  | ||||
| export const apiUrl = `${classicUrl}/api`; | ||||
| export const baseUrl = './platform'; | ||||
| export const loginUrl = `${baseUrl}/login`; | ||||
| export const logoutUrl = `${baseUrl}/logout`; | ||||
|   | ||||
| @@ -1,58 +1,8 @@ | ||||
| import test, { expect } from 'playwright/test'; | ||||
| import test from 'playwright/test'; | ||||
|  | ||||
| import { baseUrl } from './defaults.js'; | ||||
| import { doQuickLogin } from './login.js'; | ||||
|  | ||||
| /* | ||||
|  * Set the value of a global setting in the database | ||||
|  */ | ||||
| const setSettingState = async ({ | ||||
|   request, | ||||
|   setting, | ||||
|   value | ||||
| }: { | ||||
|   request: any; | ||||
|   setting: string; | ||||
|   value: any; | ||||
| }) => { | ||||
|   const url = `http://localhost:8000/api/settings/global/${setting}/`; | ||||
|  | ||||
|   const response = await request.patch(url, { | ||||
|     data: { | ||||
|       value: value | ||||
|     }, | ||||
|     headers: { | ||||
|       // Basic username: password authorization | ||||
|       Authorization: `Basic ${btoa('admin:inventree')}` | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   expect(await response.status()).toBe(200); | ||||
| }; | ||||
|  | ||||
| const setPluginState = async ({ | ||||
|   request, | ||||
|   plugin, | ||||
|   state | ||||
| }: { | ||||
|   request: any; | ||||
|   plugin: string; | ||||
|   state: boolean; | ||||
| }) => { | ||||
|   const url = `http://localhost:8000/api/plugins/${plugin}/activate/`; | ||||
|  | ||||
|   const response = await request.patch(url, { | ||||
|     data: { | ||||
|       active: state | ||||
|     }, | ||||
|     headers: { | ||||
|       // Basic username: password authorization | ||||
|       Authorization: `Basic ${btoa('admin:inventree')}` | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   expect(await response.status()).toBe(200); | ||||
| }; | ||||
| import { setPluginState, setSettingState } from './settings.js'; | ||||
|  | ||||
| test('Plugins - Panels', async ({ page, request }) => { | ||||
|   await doQuickLogin(page, 'admin', 'inventree'); | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| import { expect, test } from './baseFixtures.js'; | ||||
| import { baseUrl } from './defaults.js'; | ||||
| import { apiUrl, baseUrl } from './defaults.js'; | ||||
| import { doQuickLogin } from './login.js'; | ||||
| import { setSettingState } from './settings.js'; | ||||
|  | ||||
| test('PUI - Admin', async ({ page }) => { | ||||
|   // Note here we login with admin access | ||||
| @@ -85,6 +86,43 @@ test('PUI - Admin', async ({ page }) => { | ||||
|   await page.getByRole('button', { name: 'Submit' }).click(); | ||||
| }); | ||||
|  | ||||
| test('PUI - Admin - Barcode History', async ({ page, request }) => { | ||||
|   // Login with admin credentials | ||||
|   await doQuickLogin(page, 'admin', 'inventree'); | ||||
|  | ||||
|   // Ensure that the "save scans" setting is enabled | ||||
|   await setSettingState({ | ||||
|     request: request, | ||||
|     setting: 'BARCODE_STORE_RESULTS', | ||||
|     value: true | ||||
|   }); | ||||
|  | ||||
|   // Scan some barcodes (via API calls) | ||||
|   const barcodes = ['ABC1234', 'XYZ5678', 'QRS9012']; | ||||
|  | ||||
|   barcodes.forEach(async (barcode) => { | ||||
|     await request.post(`${apiUrl}/barcode/`, { | ||||
|       data: { | ||||
|         barcode: barcode | ||||
|       }, | ||||
|       headers: { | ||||
|         Authorization: `Basic ${btoa('admin:inventree')}` | ||||
|       } | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   await page.getByRole('button', { name: 'admin' }).click(); | ||||
|   await page.getByRole('menuitem', { name: 'Admin Center' }).click(); | ||||
|   await page.getByRole('tab', { name: 'Barcode Scans' }).click(); | ||||
|  | ||||
|   await page.waitForTimeout(2000); | ||||
|  | ||||
|   // Barcode history is displayed in table | ||||
|   barcodes.forEach(async (barcode) => { | ||||
|     await page.getByText(barcode).first().waitFor(); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| test('PUI - Admin - Unauthorized', async ({ page }) => { | ||||
|   // Try to access "admin" page with a non-staff user | ||||
|   await doQuickLogin(page, 'allaccess', 'nolimits'); | ||||
|   | ||||
							
								
								
									
										54
									
								
								src/frontend/tests/settings.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/frontend/tests/settings.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| import { expect } from 'playwright/test'; | ||||
|  | ||||
| import { apiUrl } from './defaults'; | ||||
|  | ||||
| /* | ||||
|  * Set the value of a global setting in the database | ||||
|  */ | ||||
| export const setSettingState = async ({ | ||||
|   request, | ||||
|   setting, | ||||
|   value | ||||
| }: { | ||||
|   request: any; | ||||
|   setting: string; | ||||
|   value: any; | ||||
| }) => { | ||||
|   const url = `${apiUrl}/settings/global/${setting}/`; | ||||
|  | ||||
|   const response = await request.patch(url, { | ||||
|     data: { | ||||
|       value: value | ||||
|     }, | ||||
|     headers: { | ||||
|       // Basic username: password authorization | ||||
|       Authorization: `Basic ${btoa('admin:inventree')}` | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   expect(await response.status()).toBe(200); | ||||
| }; | ||||
|  | ||||
| export const setPluginState = async ({ | ||||
|   request, | ||||
|   plugin, | ||||
|   state | ||||
| }: { | ||||
|   request: any; | ||||
|   plugin: string; | ||||
|   state: boolean; | ||||
| }) => { | ||||
|   const url = `${apiUrl}/plugins/${plugin}/activate/`; | ||||
|  | ||||
|   const response = await request.patch(url, { | ||||
|     data: { | ||||
|       active: state | ||||
|     }, | ||||
|     headers: { | ||||
|       // Basic username: password authorization | ||||
|       Authorization: `Basic ${btoa('admin:inventree')}` | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   expect(await response.status()).toBe(200); | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user