From 1e887ea01f435efd65bccd7734e8187f40907a6d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 19:25:58 +1000 Subject: [PATCH] Add owner field to stock location create/edit form (#12826) (#12836) * Add owner field to stock location create/edit form (#12537) The platform UI form for stock locations is built from the explicit field list in stockLocationFields(), which did not include 'owner'. The StockLocation model (migration 0057), LocationSerializer and the documentation all support the owner field, so restore UI parity by adding it, following the same pattern as the stock item form. * Hide owner field when stock ownership is disabled (#12537) Per review: only render the owner field in the stock location create/edit forms when the STOCK_OWNERSHIP_CONTROL global setting is enabled. stockLocationFields() becomes the useStockLocationFields() hook so the form can react to the setting, following the same pattern as the expiry date field in useStockFields(). (cherry picked from commit 028d1cba1f42e269bad91f82faf99bc3426fea43) Co-authored-by: wyyd-yxc <2868299717@qq.com> --- src/frontend/src/forms/StockForms.tsx | 13 ++++++++++++- src/frontend/src/pages/stock/LocationDetail.tsx | 4 ++-- .../src/tables/stock/StockLocationTable.tsx | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/forms/StockForms.tsx b/src/frontend/src/forms/StockForms.tsx index c79c5b4f26..a10ce019be 100644 --- a/src/frontend/src/forms/StockForms.tsx +++ b/src/frontend/src/forms/StockForms.tsx @@ -2158,7 +2158,9 @@ export function useDeleteStockItem(props: StockOperationProps) { }); } -export function stockLocationFields(): ApiFormFieldSet { +export function useStockLocationFields(): ApiFormFieldSet { + const globalSettings = useGlobalSettingsState(); + const fields: ApiFormFieldSet = { parent: { description: t`Parent stock location`, @@ -2166,6 +2168,9 @@ export function stockLocationFields(): ApiFormFieldSet { }, name: {}, description: {}, + owner: { + icon: + }, structural: {}, external: {}, custom_icon: { @@ -2174,6 +2179,12 @@ export function stockLocationFields(): ApiFormFieldSet { location_type: {} }; + // Ownership of a stock location is only relevant if + // stock ownership control is enabled + if (!globalSettings.isSet('STOCK_OWNERSHIP_CONTROL')) { + delete fields.owner; + } + return fields; } diff --git a/src/frontend/src/pages/stock/LocationDetail.tsx b/src/frontend/src/pages/stock/LocationDetail.tsx index bcaf1c08b3..87b2e39227 100644 --- a/src/frontend/src/pages/stock/LocationDetail.tsx +++ b/src/frontend/src/pages/stock/LocationDetail.tsx @@ -38,7 +38,7 @@ import { PanelGroup } from '../../components/panels/PanelGroup'; import ParametersPanel from '../../components/panels/ParametersPanel'; import SegmentedControlPanel from '../../components/panels/SegmentedControlPanel'; import LocateItemButton from '../../components/plugins/LocateItemButton'; -import { stockLocationFields } from '../../forms/StockForms'; +import { useStockLocationFields } from '../../forms/StockForms'; import { InvenTreeIcon } from '../../functions/icons'; import { useDeleteApiFormModal, @@ -217,7 +217,7 @@ export default function Stock() { url: ApiEndpoints.stock_location_list, pk: id, title: t`Edit Stock Location`, - fields: stockLocationFields(), + fields: useStockLocationFields(), onFormSuccess: refreshInstance }); diff --git a/src/frontend/src/tables/stock/StockLocationTable.tsx b/src/frontend/src/tables/stock/StockLocationTable.tsx index d86a83ac73..35fd16617d 100644 --- a/src/frontend/src/tables/stock/StockLocationTable.tsx +++ b/src/frontend/src/tables/stock/StockLocationTable.tsx @@ -18,7 +18,7 @@ import { DescriptionColumn } from '../../components/tables/ColumnRenderers'; import { InvenTreeTable } from '../../components/tables/InvenTreeTable'; -import { stockLocationFields } from '../../forms/StockForms'; +import { useStockLocationFields } from '../../forms/StockForms'; import { InvenTreeIcon } from '../../functions/icons'; import { useBulkEditApiFormModal, @@ -109,7 +109,7 @@ export function StockLocationTable({ parentId }: Readonly<{ parentId?: any }>) { const newLocation = useCreateApiFormModal({ url: ApiEndpoints.stock_location_list, title: t`Add Stock Location`, - fields: stockLocationFields(), + fields: useStockLocationFields(), focus: 'name', initialData: { parent: parentId @@ -126,7 +126,7 @@ export function StockLocationTable({ parentId }: Readonly<{ parentId?: any }>) { url: ApiEndpoints.stock_location_list, pk: selectedLocation, title: t`Edit Stock Location`, - fields: stockLocationFields(), + fields: useStockLocationFields(), onFormSuccess: (record: any) => table.updateRecord(record) });