mirror of
https://github.com/inventree/InvenTree.git
synced 2025-11-14 03:46:44 +00:00
[UI] Sales order button (#9938)
* Refactor stock actions into a hook * Cleanup hooks * Allow transfer of "incomplete" outputs * Simplify even further * Enable transfer of stock allocated to build order * Remove StockItemBriefSerializer entirely * stock actions for items allocated to sales order * Refactor <PartDetail> page * Refactor <StockDetail> * Refactor <LocationDetail> * Bump API version * SO button text - Observe the "SALESORDER_SHIP_COMPLETE" value * Fix palywright tests
This commit is contained in:
@@ -6,10 +6,12 @@ import { ModelType } from '@lib/enums/ModelType';
|
||||
import { UserRoles } from '@lib/enums/Roles';
|
||||
import { apiUrl } from '@lib/functions/Api';
|
||||
import type { TableFilter } from '@lib/types/Filters';
|
||||
import type { StockOperationProps } from '../../forms/StockForms';
|
||||
import {
|
||||
useDeleteApiFormModal,
|
||||
useEditApiFormModal
|
||||
} from '../../hooks/UseForm';
|
||||
import { useStockAdjustActions } from '../../hooks/UseStockAdjustActions';
|
||||
import { useTable } from '../../hooks/UseTable';
|
||||
import { useUserState } from '../../states/UserState';
|
||||
import type { TableColumn } from '../Column';
|
||||
@@ -178,6 +180,37 @@ export default function BuildAllocatedStockTable({
|
||||
table: table
|
||||
});
|
||||
|
||||
const stockOperationProps: StockOperationProps = useMemo(() => {
|
||||
// Extract stock items from the selected records
|
||||
// Note that the table is actually a list of BuildItem instances,
|
||||
// so we need to reconstruct the stock item details
|
||||
const stockItems: any[] = table.selectedRecords
|
||||
.filter((item: any) => !!item.stock_item_detail)
|
||||
.map((item: any) => {
|
||||
return {
|
||||
...item.stock_item_detail,
|
||||
part_detail: item.part_detail,
|
||||
location_detail: item.location_detail
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
items: stockItems,
|
||||
model: ModelType.stockitem,
|
||||
refresh: table.refreshTable
|
||||
};
|
||||
}, [table.selectedRecords, table.refreshTable]);
|
||||
|
||||
const stockAdjustActions = useStockAdjustActions({
|
||||
formProps: stockOperationProps,
|
||||
merge: false,
|
||||
assign: false,
|
||||
delete: false,
|
||||
add: false,
|
||||
count: false,
|
||||
remove: false
|
||||
});
|
||||
|
||||
const rowActions = useCallback(
|
||||
(record: any): RowAction[] => {
|
||||
return [
|
||||
@@ -200,10 +233,15 @@ export default function BuildAllocatedStockTable({
|
||||
[user]
|
||||
);
|
||||
|
||||
const tableActions = useMemo(() => {
|
||||
return [stockAdjustActions.dropdown];
|
||||
}, [stockAdjustActions.dropdown]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{editItem.modal}
|
||||
{deleteItem.modal}
|
||||
{stockAdjustActions.modals.map((modal) => modal.modal)}
|
||||
<InvenTreeTable
|
||||
tableState={table}
|
||||
url={apiUrl(ApiEndpoints.build_item_list)}
|
||||
@@ -223,6 +261,7 @@ export default function BuildAllocatedStockTable({
|
||||
enableDownload: true,
|
||||
enableSelection: allowEdit && user.hasDeleteRole(UserRoles.build),
|
||||
rowActions: rowActions,
|
||||
tableActions: tableActions,
|
||||
tableFilters: tableFilters,
|
||||
modelField: modelField ?? 'stock_item',
|
||||
modelType: modelTarget ?? ModelType.stockitem
|
||||
|
||||
Reference in New Issue
Block a user