mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-10 06:37:17 +00:00
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:
@@ -2180,7 +2180,9 @@ export function useDeleteStockItem(props: StockOperationProps) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stockLocationFields(): ApiFormFieldSet {
|
export function useStockLocationFields(): ApiFormFieldSet {
|
||||||
|
const globalSettings = useGlobalSettingsState();
|
||||||
|
|
||||||
const fields: ApiFormFieldSet = {
|
const fields: ApiFormFieldSet = {
|
||||||
parent: {
|
parent: {
|
||||||
description: t`Parent stock location`,
|
description: t`Parent stock location`,
|
||||||
@@ -2188,6 +2190,9 @@ export function stockLocationFields(): ApiFormFieldSet {
|
|||||||
},
|
},
|
||||||
name: {},
|
name: {},
|
||||||
description: {},
|
description: {},
|
||||||
|
owner: {
|
||||||
|
icon: <IconUsersGroup />
|
||||||
|
},
|
||||||
structural: {},
|
structural: {},
|
||||||
external: {},
|
external: {},
|
||||||
custom_icon: {
|
custom_icon: {
|
||||||
@@ -2196,6 +2201,12 @@ export function stockLocationFields(): ApiFormFieldSet {
|
|||||||
location_type: {}
|
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;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import { PanelGroup } from '../../components/panels/PanelGroup';
|
|||||||
import ParametersPanel from '../../components/panels/ParametersPanel';
|
import ParametersPanel from '../../components/panels/ParametersPanel';
|
||||||
import SegmentedControlPanel from '../../components/panels/SegmentedControlPanel';
|
import SegmentedControlPanel from '../../components/panels/SegmentedControlPanel';
|
||||||
import LocateItemButton from '../../components/plugins/LocateItemButton';
|
import LocateItemButton from '../../components/plugins/LocateItemButton';
|
||||||
import { stockLocationFields } from '../../forms/StockForms';
|
import { useStockLocationFields } from '../../forms/StockForms';
|
||||||
import { InvenTreeIcon } from '../../functions/icons';
|
import { InvenTreeIcon } from '../../functions/icons';
|
||||||
import {
|
import {
|
||||||
useDeleteApiFormModal,
|
useDeleteApiFormModal,
|
||||||
@@ -224,7 +224,7 @@ export default function Stock() {
|
|||||||
url: ApiEndpoints.stock_location_list,
|
url: ApiEndpoints.stock_location_list,
|
||||||
pk: id,
|
pk: id,
|
||||||
title: t`Edit Stock Location`,
|
title: t`Edit Stock Location`,
|
||||||
fields: stockLocationFields(),
|
fields: useStockLocationFields(),
|
||||||
onFormSuccess: refreshInstance
|
onFormSuccess: refreshInstance
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
DescriptionColumn
|
DescriptionColumn
|
||||||
} from '../../components/tables/ColumnRenderers';
|
} from '../../components/tables/ColumnRenderers';
|
||||||
import { InvenTreeTable } from '../../components/tables/InvenTreeTable';
|
import { InvenTreeTable } from '../../components/tables/InvenTreeTable';
|
||||||
import { stockLocationFields } from '../../forms/StockForms';
|
import { useStockLocationFields } from '../../forms/StockForms';
|
||||||
import { InvenTreeIcon } from '../../functions/icons';
|
import { InvenTreeIcon } from '../../functions/icons';
|
||||||
import {
|
import {
|
||||||
useBulkEditApiFormModal,
|
useBulkEditApiFormModal,
|
||||||
@@ -109,7 +109,7 @@ export function StockLocationTable({ parentId }: Readonly<{ parentId?: any }>) {
|
|||||||
const newLocation = useCreateApiFormModal({
|
const newLocation = useCreateApiFormModal({
|
||||||
url: ApiEndpoints.stock_location_list,
|
url: ApiEndpoints.stock_location_list,
|
||||||
title: t`Add Stock Location`,
|
title: t`Add Stock Location`,
|
||||||
fields: stockLocationFields(),
|
fields: useStockLocationFields(),
|
||||||
focus: 'name',
|
focus: 'name',
|
||||||
initialData: {
|
initialData: {
|
||||||
parent: parentId
|
parent: parentId
|
||||||
@@ -126,7 +126,7 @@ export function StockLocationTable({ parentId }: Readonly<{ parentId?: any }>) {
|
|||||||
url: ApiEndpoints.stock_location_list,
|
url: ApiEndpoints.stock_location_list,
|
||||||
pk: selectedLocation,
|
pk: selectedLocation,
|
||||||
title: t`Edit Stock Location`,
|
title: t`Edit Stock Location`,
|
||||||
fields: stockLocationFields(),
|
fields: useStockLocationFields(),
|
||||||
onFormSuccess: (record: any) => table.updateRecord(record)
|
onFormSuccess: (record: any) => table.updateRecord(record)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user