[UI] Show linked barcode string on stock detail page (#11745)#12354
[UI] Show linked barcode string on stock detail page (#11745)#12354mahekp05 wants to merge 8 commits into
Conversation
…barcode-ui # Conflicts: # src/frontend/src/pages/stock/StockDetail.tsx
Add a backend API test asserting the read-only barcode_data field is exposed by StockItemSerializer, and a Playwright test covering the link -> display -> unlink flow on the stock detail page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
There was a problem hiding this comment.
Pull request overview
Restores visibility of the linked (third-party) barcode string on the Stock Item detail page by exposing barcode_data via the StockItem API and rendering it (copyable) in the frontend, with regression coverage across backend and Playwright E2E tests.
Changes:
- Exposes
barcode_dataonStockItemSerializeras a read-only field and bumps the API version. - Displays a conditional “Linked Barcode” (copyable) field on the stock item detail page when
barcode_datais present. - Adds backend and Playwright regression tests for the link → display → unlink flow.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/frontend/tests/pages/pui_stock.spec.ts | Adds Playwright regression test verifying linked barcode visibility toggles with link/unlink actions. |
| src/frontend/src/pages/stock/StockDetail.tsx | Renders “Linked Barcode” detail field (copyable) when stockitem.barcode_data is present. |
| src/backend/InvenTree/stock/test_api.py | Adds API regression test ensuring barcode_data is exposed and remains read-only via PATCH. |
| src/backend/InvenTree/stock/serializers.py | Adds barcode_data to serializer output and marks it read-only. |
| src/backend/InvenTree/InvenTree/api_version.py | Increments API version and documents the change in the API version text. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| v520 -> 2026-07-10 : https://github.com/inventree/InvenTree/pull/TODO | ||
| - Adds read-only "barcode_data" field to the StockItem API endpoint |
| // Link a custom barcode via the barcode actions dropdown | ||
| await page.getByLabel('action-menu-barcode-actions').click(); | ||
| await page.getByLabel('action-menu-barcode-actions-link-barcode').click(); | ||
|
|
||
| // Enter the barcode data via the keyboard input and submit | ||
| await page.getByLabel('barcode-input-scanner').click(); | ||
| await page.getByLabel('barcode-scan-keyboard-input').fill('TEST-123'); | ||
| await page.getByRole('button', { name: 'Link', exact: true }).click(); |
|
Hi @mahekp05 thanks for the PR! If we are going to fix this we should do it in the general case - not just for the StockItem detail. There are many other pages which support custom barcode data, so these changes should be applied to those too, and also in a generic way |
Thanks for the feedback! I've reworked this to apply generically across all models that support custom barcodes ( ApproachBackend — one shared serializer mixin Frontend — one shared helper CoverageThe linked barcode string now displays on: Part, StockItem, StockLocation, Build, SupplierPart, ManufacturerPart, PurchaseOrder, SalesOrder, ReturnOrder, TransferOrder, SalesOrderShipment. Files changedBackend
Frontend
Tests
Open to feedback — happy to adjust the placement, naming, or approach if you'd prefer it done differently, or if any other changes are needed. |
| Note: The serializer's Meta.fields must include 'barcode_data' for it to appear. | ||
| The field is read-only here; barcodes are assigned via the barcode link endpoints. |
There was a problem hiding this comment.
can we add a check if the Meta is set correctly? Either in init or as a django system check?
There was a problem hiding this comment.
Yes, I just added a check in BarcodeSerializerMixin.init to make sure the serializer's model supports barcodes and that barcode_data is included in Meta.fields. If either is configured incorrectly, it raises ImproperlyConfigured. I also added tests for both cases.
I went with the init-time check so the configuration is validated whenever the serializer is instantiated
| * | ||
| * The field is copyable and only rendered when a barcode is linked to the instance. | ||
| */ | ||
| export function barcodeDataField(instance: any): DetailsField { |
There was a problem hiding this comment.
@SchrodingersGat do we need to do a memo trick here?
Description
Restores the linked (third-party) barcode string on the stock item detail page, which was visible pre-1.0 but lost after the UI rewrite.
Fixes #11745
Changes
barcode_dataas a read-only field onStockItemSerializerTests
barcode_datais exposed and read-only