mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-04 06:00:38 +00:00
Allow stock adjustment from "category" detail view (#12256)
This commit is contained in:
@@ -16,6 +16,7 @@ import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
|||||||
import { ModelType } from '@lib/enums/ModelType';
|
import { ModelType } from '@lib/enums/ModelType';
|
||||||
import { UserRoles } from '@lib/enums/Roles';
|
import { UserRoles } from '@lib/enums/Roles';
|
||||||
import { getDetailUrl } from '@lib/functions/Navigation';
|
import { getDetailUrl } from '@lib/functions/Navigation';
|
||||||
|
import type { StockOperationProps } from '@lib/types/Forms';
|
||||||
import type { PanelType } from '@lib/types/Panel';
|
import type { PanelType } from '@lib/types/Panel';
|
||||||
import { useLocalStorage } from '@mantine/hooks';
|
import { useLocalStorage } from '@mantine/hooks';
|
||||||
import AdminButton from '../../components/buttons/AdminButton';
|
import AdminButton from '../../components/buttons/AdminButton';
|
||||||
@@ -43,6 +44,7 @@ import {
|
|||||||
useEditApiFormModal
|
useEditApiFormModal
|
||||||
} from '../../hooks/UseForm';
|
} from '../../hooks/UseForm';
|
||||||
import { useInstance } from '../../hooks/UseInstance';
|
import { useInstance } from '../../hooks/UseInstance';
|
||||||
|
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
|
||||||
import { useUserSettingsState } from '../../states/SettingsStates';
|
import { useUserSettingsState } from '../../states/SettingsStates';
|
||||||
import { useUserState } from '../../states/UserState';
|
import { useUserState } from '../../states/UserState';
|
||||||
import ParametricPartTable from '../../tables/part/ParametricPartTable';
|
import ParametricPartTable from '../../tables/part/ParametricPartTable';
|
||||||
@@ -82,6 +84,28 @@ export default function CategoryDetail() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const stockOperationProps: StockOperationProps = useMemo(() => {
|
||||||
|
return {
|
||||||
|
refresh: refreshInstance,
|
||||||
|
filters: {
|
||||||
|
category: category.pk,
|
||||||
|
in_stock: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [category]);
|
||||||
|
|
||||||
|
const stockAdjustActions = useStockAdjustActions({
|
||||||
|
formProps: stockOperationProps,
|
||||||
|
enabled: true,
|
||||||
|
add: false,
|
||||||
|
remove: false,
|
||||||
|
changeStatus: false,
|
||||||
|
changeBatch: false,
|
||||||
|
delete: false,
|
||||||
|
merge: false,
|
||||||
|
assign: false
|
||||||
|
});
|
||||||
|
|
||||||
const detailsPanel = useMemo(() => {
|
const detailsPanel = useMemo(() => {
|
||||||
if (id && instanceQuery.isFetching) {
|
if (id && instanceQuery.isFetching) {
|
||||||
return <Skeleton />;
|
return <Skeleton />;
|
||||||
@@ -241,6 +265,7 @@ export default function CategoryDetail() {
|
|||||||
refreshInstance();
|
refreshInstance();
|
||||||
}}
|
}}
|
||||||
/>,
|
/>,
|
||||||
|
stockAdjustActions.dropdown,
|
||||||
<OptionsActionDropdown
|
<OptionsActionDropdown
|
||||||
key='category-actions'
|
key='category-actions'
|
||||||
tooltip={t`Category Actions`}
|
tooltip={t`Category Actions`}
|
||||||
@@ -258,7 +283,7 @@ export default function CategoryDetail() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
];
|
];
|
||||||
}, [id, user, category.pk, category.starred]);
|
}, [id, user, category.pk, category.starred, stockAdjustActions.dropdown]);
|
||||||
|
|
||||||
const [partsView, setPartsView] = useLocalStorage<string>({
|
const [partsView, setPartsView] = useLocalStorage<string>({
|
||||||
key: 'category-parts-view',
|
key: 'category-parts-view',
|
||||||
@@ -367,6 +392,7 @@ export default function CategoryDetail() {
|
|||||||
<>
|
<>
|
||||||
{editCategory.modal}
|
{editCategory.modal}
|
||||||
{deleteCategory.modal}
|
{deleteCategory.modal}
|
||||||
|
{stockAdjustActions.modals.map((modal) => modal.modal)}
|
||||||
<InstanceDetail
|
<InstanceDetail
|
||||||
query={instanceQuery}
|
query={instanceQuery}
|
||||||
requiredRole={UserRoles.part_category}
|
requiredRole={UserRoles.part_category}
|
||||||
|
|||||||
Reference in New Issue
Block a user