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',
|
return_order = 'return_order',
|
||||||
sales_order = 'sales_order',
|
sales_order = 'sales_order',
|
||||||
stock = 'stock',
|
stock = 'stock',
|
||||||
stock_location = 'stocklocation',
|
stock_location = 'stock_location',
|
||||||
stocktake = 'stocktake'
|
stocktake = 'stocktake'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { useMemo, useState } from 'react';
|
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 { ApiEndpoints } from '../enums/ApiEndpoints';
|
||||||
import { useCreateApiFormModal, useEditApiFormModal } from '../hooks/UseForm';
|
import { useCreateApiFormModal, useEditApiFormModal } from '../hooks/UseForm';
|
||||||
|
|
||||||
@ -37,6 +40,13 @@ export function useStockFields({
|
|||||||
part_detail: true,
|
part_detail: true,
|
||||||
supplier_detail: true,
|
supplier_detail: true,
|
||||||
...(part ? { part } : {})
|
...(part ? { part } : {})
|
||||||
|
},
|
||||||
|
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||||
|
if (value.data.part) {
|
||||||
|
value.filters['part'] = value.data.part;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.filters;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
use_pack_size: {
|
use_pack_size: {
|
||||||
|
@ -3,12 +3,17 @@ import { Group, Text } from '@mantine/core';
|
|||||||
import { ReactNode, useMemo } from 'react';
|
import { ReactNode, useMemo } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { AddItemButton } from '../../components/buttons/AddItemButton';
|
||||||
import { formatCurrency, renderDate } from '../../defaults/formatters';
|
import { formatCurrency, renderDate } from '../../defaults/formatters';
|
||||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||||
import { ModelType } from '../../enums/ModelType';
|
import { ModelType } from '../../enums/ModelType';
|
||||||
|
import { UserRoles } from '../../enums/Roles';
|
||||||
|
import { useStockFields } from '../../forms/StockForms';
|
||||||
import { getDetailUrl } from '../../functions/urls';
|
import { getDetailUrl } from '../../functions/urls';
|
||||||
|
import { useCreateApiFormModal } from '../../hooks/UseForm';
|
||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
import { apiUrl } from '../../states/ApiState';
|
import { apiUrl } from '../../states/ApiState';
|
||||||
|
import { useUserState } from '../../states/UserState';
|
||||||
import { TableColumn } from '../Column';
|
import { TableColumn } from '../Column';
|
||||||
import {
|
import {
|
||||||
DescriptionColumn,
|
DescriptionColumn,
|
||||||
@ -329,27 +334,58 @@ export function StockItemTable({ params = {} }: { params?: any }) {
|
|||||||
let tableFilters = useMemo(() => stockItemTableFilters(), []);
|
let tableFilters = useMemo(() => stockItemTableFilters(), []);
|
||||||
|
|
||||||
const table = useTable('stockitems');
|
const table = useTable('stockitems');
|
||||||
|
const user = useUserState();
|
||||||
const navigate = useNavigate();
|
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 (
|
return (
|
||||||
<InvenTreeTable
|
<>
|
||||||
url={apiUrl(ApiEndpoints.stock_item_list)}
|
{newStockItem.modal}
|
||||||
tableState={table}
|
<InvenTreeTable
|
||||||
columns={tableColumns}
|
url={apiUrl(ApiEndpoints.stock_item_list)}
|
||||||
props={{
|
tableState={table}
|
||||||
enableDownload: true,
|
columns={tableColumns}
|
||||||
enableSelection: false,
|
props={{
|
||||||
tableFilters: tableFilters,
|
enableDownload: true,
|
||||||
onRowClick: (record) =>
|
enableSelection: false,
|
||||||
navigate(getDetailUrl(ModelType.stockitem, record.pk)),
|
tableFilters: tableFilters,
|
||||||
params: {
|
tableActions: tableActions,
|
||||||
...params,
|
onRowClick: (record) =>
|
||||||
part_detail: true,
|
navigate(getDetailUrl(ModelType.stockitem, record.pk)),
|
||||||
location_detail: true,
|
params: {
|
||||||
supplier_part_detail: true
|
...params,
|
||||||
}
|
part_detail: true,
|
||||||
}}
|
location_detail: true,
|
||||||
/>
|
supplier_part_detail: true
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ export function StockLocationTable({ parentId }: { parentId?: any }) {
|
|||||||
<AddItemButton
|
<AddItemButton
|
||||||
tooltip={t`Add Stock Location`}
|
tooltip={t`Add Stock Location`}
|
||||||
onClick={() => newLocation.open()}
|
onClick={() => newLocation.open()}
|
||||||
disabled={!can_add}
|
hidden={!can_add}
|
||||||
/>
|
/>
|
||||||
];
|
];
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
Loading…
Reference in New Issue
Block a user