Skip to content

[UI] Show linked barcode string on stock detail page (#11745)#12354

Open
mahekp05 wants to merge 8 commits into
inventree:masterfrom
mahekp05:fix-11745-linked-barcode-ui
Open

[UI] Show linked barcode string on stock detail page (#11745)#12354
mahekp05 wants to merge 8 commits into
inventree:masterfrom
mahekp05:fix-11745-linked-barcode-ui

Conversation

@mahekp05

Copy link
Copy Markdown

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

  • Expose barcode_data as a read-only field on StockItemSerializer
  • Display a "Linked Barcode" field (copyable) on the stock detail page, shown only when a barcode is linked

Tests

  • Backend API test asserting barcode_data is exposed and read-only
  • Playwright test covering the link → display → unlink flow

mahekp05 and others added 4 commits June 21, 2026 16:11
…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>
Copilot AI review requested due to automatic review settings July 10, 2026 23:19
@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 162b314
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a566ca15a334b000893b69a

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_data on StockItemSerializer as a read-only field and bumps the API version.
  • Displays a conditional “Linked Barcode” (copyable) field on the stock item detail page when barcode_data is 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.

Comment on lines +9 to +10
v520 -> 2026-07-10 : https://github.com/inventree/InvenTree/pull/TODO
- Adds read-only "barcode_data" field to the StockItem API endpoint
Comment on lines +344 to +351
// 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();
@SchrodingersGat

Copy link
Copy Markdown
Member

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

@mahekp05

Copy link
Copy Markdown
Author

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 (InvenTreeBarcodeMixin), rather than special-casing StockItem.

Approach

Backend — one shared serializer mixin
Added BarcodeSerializerMixin in InvenTree/serializers.py, which declares the read-only barcode_data field once. Each barcode-supporting serializer mixes it in and adds 'barcode_data' to its Meta.fields. For the order types this is done once on the shared AbstractOrderSerializer / order_fields(), so PurchaseOrder, SalesOrder, ReturnOrder and
TransferOrder are all covered without duplication.

Frontend — one shared helper
Added barcodeDataField(instance) in components/details/Details.tsx, which returns the copyable "Linked Barcode" detail field (only shown when a barcode is linked). Each detail page spreads it into its details grid (consistently in the top-left panel). The original inline StockItem block was refactored to use this helper too, so nothing is special-cased.

Coverage

The linked barcode string now displays on: Part, StockItem, StockLocation, Build, SupplierPart, ManufacturerPart, PurchaseOrder, SalesOrder, ReturnOrder, TransferOrder, SalesOrderShipment.

Files changed

Backend

  • InvenTree/serializers.py — new BarcodeSerializerMixin
  • stock/serializers.py, part/serializers.py, build/serializers.py,
    company/serializers.py, order/serializers.py — mixin wired in + barcode_data field
  • InvenTree/api_version.py — API v520 changelog
  • InvenTree/test_serializers.py — new test asserting barcode_data is exposed & read-only
    across all barcode serializers

Frontend

  • components/details/Details.tsx — new barcodeDataField helper
  • 10 detail pages wired to use it (Stock, Part, Location, Build, Manufacturer/Supplier part,
    Purchase/Sales/Return/Transfer order)

Tests

  • Generic backend test (BarcodeSerializerMixinTest) covering all 11 serializers
  • Existing StockItem end-to-end API test retained
  • Playwright test covering the link → display → unlink flow

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.

@matmair matmair left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general

Comment on lines +844 to +845
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a check if the Meta is set correctly? Either in init or as a django system check?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SchrodingersGat do we need to do a memo trick here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Show linked barcode string in user interface

4 participants