mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
[PUI] Stock item forms (#6597)
* Implement "new stock item" button * Fix adjustFilters for StockForm * Fix imports
This commit is contained in:
parent
2e81a304d1
commit
38d013ffe2
@ -10,7 +10,7 @@ export enum UserRoles {
|
||||
return_order = 'return_order',
|
||||
sales_order = 'sales_order',
|
||||
stock = 'stock',
|
||||
stock_location = 'stocklocation',
|
||||
stock_location = 'stock_location',
|
||||
stocktake = 'stocktake'
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { t } from '@lingui/macro';
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField';
|
||||
import {
|
||||
ApiFormAdjustFilterType,
|
||||
ApiFormFieldSet
|
||||
} from '../components/forms/fields/ApiFormField';
|
||||
import { ApiEndpoints } from '../enums/ApiEndpoints';
|
||||
import { useCreateApiFormModal, useEditApiFormModal } from '../hooks/UseForm';
|
||||
|
||||
@ -37,6 +40,13 @@ export function useStockFields({
|
||||
part_detail: true,
|
||||
supplier_detail: true,
|
||||
...(part ? { part } : {})
|
||||
},
|
||||
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||
if (value.data.part) {
|
||||
value.filters['part'] = value.data.part;
|
||||
}
|
||||
|
||||
return value.filters;
|
||||
}
|
||||
},
|
||||
use_pack_size: {
|
||||
|
@ -3,12 +3,17 @@ import { Group, Text } from '@mantine/core';
|
||||
import { ReactNode, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { AddItemButton } from '../../components/buttons/AddItemButton';
|
||||
import { formatCurrency, renderDate } from '../../defaults/formatters';
|
||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||
import { ModelType } from '../../enums/ModelType';
|
||||
import { UserRoles } from '../../enums/Roles';
|
||||
import { useStockFields } from '../../forms/StockForms';
|
||||
import { getDetailUrl } from '../../functions/urls';
|
||||
import { useCreateApiFormModal } from '../../hooks/UseForm';
|
||||
import { useTable } from '../../hooks/UseTable';
|
||||
import { apiUrl } from '../../states/ApiState';
|
||||
import { useUserState } from '../../states/UserState';
|
||||
import { TableColumn } from '../Column';
|
||||
import {
|
||||
DescriptionColumn,
|
||||
@ -329,27 +334,58 @@ export function StockItemTable({ params = {} }: { params?: any }) {
|
||||
let tableFilters = useMemo(() => stockItemTableFilters(), []);
|
||||
|
||||
const table = useTable('stockitems');
|
||||
|
||||
const user = useUserState();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const stockItemFields = useStockFields({ create: true });
|
||||
|
||||
const newStockItem = useCreateApiFormModal({
|
||||
url: ApiEndpoints.stock_item_list,
|
||||
title: t`Add Stock Item`,
|
||||
fields: stockItemFields,
|
||||
initialData: {
|
||||
part: params.part,
|
||||
location: params.location
|
||||
},
|
||||
onFormSuccess: (data: any) => {
|
||||
if (data.pk) {
|
||||
navigate(getDetailUrl(ModelType.stockitem, data.pk));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const tableActions = useMemo(() => {
|
||||
return [
|
||||
<AddItemButton
|
||||
hidden={!user.hasAddRole(UserRoles.stock)}
|
||||
tooltip={t`Add Stock Item`}
|
||||
onClick={() => newStockItem.open()}
|
||||
/>
|
||||
];
|
||||
}, [user]);
|
||||
|
||||
return (
|
||||
<InvenTreeTable
|
||||
url={apiUrl(ApiEndpoints.stock_item_list)}
|
||||
tableState={table}
|
||||
columns={tableColumns}
|
||||
props={{
|
||||
enableDownload: true,
|
||||
enableSelection: false,
|
||||
tableFilters: tableFilters,
|
||||
onRowClick: (record) =>
|
||||
navigate(getDetailUrl(ModelType.stockitem, record.pk)),
|
||||
params: {
|
||||
...params,
|
||||
part_detail: true,
|
||||
location_detail: true,
|
||||
supplier_part_detail: true
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<>
|
||||
{newStockItem.modal}
|
||||
<InvenTreeTable
|
||||
url={apiUrl(ApiEndpoints.stock_item_list)}
|
||||
tableState={table}
|
||||
columns={tableColumns}
|
||||
props={{
|
||||
enableDownload: true,
|
||||
enableSelection: false,
|
||||
tableFilters: tableFilters,
|
||||
tableActions: tableActions,
|
||||
onRowClick: (record) =>
|
||||
navigate(getDetailUrl(ModelType.stockitem, record.pk)),
|
||||
params: {
|
||||
...params,
|
||||
part_detail: true,
|
||||
location_detail: true,
|
||||
supplier_part_detail: true
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ export function StockLocationTable({ parentId }: { parentId?: any }) {
|
||||
<AddItemButton
|
||||
tooltip={t`Add Stock Location`}
|
||||
onClick={() => newLocation.open()}
|
||||
disabled={!can_add}
|
||||
hidden={!can_add}
|
||||
/>
|
||||
];
|
||||
}, [user]);
|
||||
|
Loading…
Reference in New Issue
Block a user