From 028d1cba1f42e269bad91f82faf99bc3426fea43 Mon Sep 17 00:00:00 2001 From: wyyd-yxc <2868299717@qq.com> Date: Thu, 10 Sep 2026 13:40:07 +0800 Subject: [PATCH] Add owner field to stock location create/edit form (#12826) * 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(). --- 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 79215f379a..a8f015ba4f 100644 --- a/src/frontend/src/forms/StockForms.tsx +++ b/src/frontend/src/forms/StockForms.tsx @@ -2180,7 +2180,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`, @@ -2188,6 +2190,9 @@ export function stockLocationFields(): ApiFormFieldSet { }, name: {}, description: {}, + owner: { + icon: + }, structural: {}, external: {}, custom_icon: { @@ -2196,6 +2201,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 e2dba4347e..1342698721 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, @@ -224,7 +224,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) });