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().
This commit is contained in:
wyyd-yxc
2026-09-10 15:40:07 +10:00
committed by GitHub
parent e8af71ae5a
commit 028d1cba1f
3 changed files with 17 additions and 6 deletions
+12 -1
View File
@@ -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: <IconUsersGroup />
},
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;
}
@@ -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
});
@@ -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)
});