Allow stock adjustment from "category" detail view
This commit is contained in:
parent
496b20e08f
commit
d91f7be91d
|
|
@ -223,6 +223,6 @@ export type StockOperationProps = {
|
|||
items?: any[];
|
||||
pk?: number;
|
||||
filters?: any;
|
||||
model: ModelType.stockitem | 'location' | ModelType.part;
|
||||
model: ModelType.stockitem | 'location' | 'category' | ModelType.part;
|
||||
refresh: () => void;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
|||
import { ModelType } from '@lib/enums/ModelType';
|
||||
import { UserRoles } from '@lib/enums/Roles';
|
||||
import { getDetailUrl } from '@lib/functions/Navigation';
|
||||
import type { StockOperationProps } from '@lib/types/Forms';
|
||||
import type { PanelType } from '@lib/types/Panel';
|
||||
import { useLocalStorage } from '@mantine/hooks';
|
||||
import AdminButton from '../../components/buttons/AdminButton';
|
||||
|
|
@ -43,6 +44,7 @@ import {
|
|||
useEditApiFormModal
|
||||
} from '../../hooks/UseForm';
|
||||
import { useInstance } from '../../hooks/UseInstance';
|
||||
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
|
||||
import { useUserSettingsState } from '../../states/SettingsStates';
|
||||
import { useUserState } from '../../states/UserState';
|
||||
import ParametricPartTable from '../../tables/part/ParametricPartTable';
|
||||
|
|
@ -82,6 +84,29 @@ export default function CategoryDetail() {
|
|||
}
|
||||
});
|
||||
|
||||
const stockOperationProps: StockOperationProps = useMemo(() => {
|
||||
return {
|
||||
pk: category.pk,
|
||||
model: 'category',
|
||||
refresh: refreshInstance,
|
||||
filters: {
|
||||
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(() => {
|
||||
if (id && instanceQuery.isFetching) {
|
||||
return <Skeleton />;
|
||||
|
|
@ -241,6 +266,7 @@ export default function CategoryDetail() {
|
|||
refreshInstance();
|
||||
}}
|
||||
/>,
|
||||
stockAdjustActions.dropdown,
|
||||
<OptionsActionDropdown
|
||||
key='category-actions'
|
||||
tooltip={t`Category Actions`}
|
||||
|
|
@ -258,7 +284,7 @@ export default function CategoryDetail() {
|
|||
]}
|
||||
/>
|
||||
];
|
||||
}, [id, user, category.pk, category.starred]);
|
||||
}, [id, user, category.pk, category.starred, stockAdjustActions.dropdown]);
|
||||
|
||||
const [partsView, setPartsView] = useLocalStorage<string>({
|
||||
key: 'category-parts-view',
|
||||
|
|
@ -367,6 +393,7 @@ export default function CategoryDetail() {
|
|||
<>
|
||||
{editCategory.modal}
|
||||
{deleteCategory.modal}
|
||||
{stockAdjustActions.modals.map((modal) => modal.modal)}
|
||||
<InstanceDetail
|
||||
query={instanceQuery}
|
||||
requiredRole={UserRoles.part_category}
|
||||
|
|
|
|||
Loading…
Reference in New Issue