mirror of
https://github.com/inventree/InvenTree.git
synced 2026-06-06 08:54:24 +00:00
* Fix: Apply default location correctly in Return Stock form (#11568) * Fix: Apply prek import ordering
This commit is contained in:
committed by
GitHub
parent
4b415cb8ae
commit
956468eb84
@@ -1,3 +1,16 @@
|
|||||||
|
import { ActionButton } from '@lib/components/ActionButton';
|
||||||
|
import { StylishText } from '@lib/components/StylishText';
|
||||||
|
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||||
|
import { ModelType } from '@lib/enums/ModelType';
|
||||||
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
|
import { getDetailUrl } from '@lib/functions/Navigation';
|
||||||
|
import type {
|
||||||
|
ApiFormAdjustFilterType,
|
||||||
|
ApiFormFieldChoice,
|
||||||
|
ApiFormFieldSet,
|
||||||
|
ApiFormModalProps,
|
||||||
|
StockOperationProps
|
||||||
|
} from '@lib/types/Forms';
|
||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
@@ -20,27 +33,13 @@ import {
|
|||||||
IconUsersGroup
|
IconUsersGroup
|
||||||
} from '@tabler/icons-react';
|
} from '@tabler/icons-react';
|
||||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
||||||
import { type JSX, Suspense, useEffect, useMemo, useState } from 'react';
|
|
||||||
|
|
||||||
import { ActionButton } from '@lib/components/ActionButton';
|
|
||||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
|
||||||
import { ModelType } from '@lib/enums/ModelType';
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import { type JSX, Suspense, useEffect, useMemo, useState } from 'react';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { api } from '../App';
|
import { api } from '../App';
|
||||||
import RemoveRowButton from '../components/buttons/RemoveRowButton';
|
import RemoveRowButton from '../components/buttons/RemoveRowButton';
|
||||||
import { StandaloneField } from '../components/forms/StandaloneField';
|
import { StandaloneField } from '../components/forms/StandaloneField';
|
||||||
|
|
||||||
import { StylishText } from '@lib/components/StylishText';
|
|
||||||
import { apiUrl } from '@lib/functions/Api';
|
|
||||||
import { getDetailUrl } from '@lib/functions/Navigation';
|
|
||||||
import type {
|
|
||||||
ApiFormAdjustFilterType,
|
|
||||||
ApiFormFieldChoice,
|
|
||||||
ApiFormFieldSet,
|
|
||||||
ApiFormModalProps,
|
|
||||||
StockOperationProps
|
|
||||||
} from '@lib/types/Forms';
|
|
||||||
import {
|
import {
|
||||||
TableFieldExtraRow,
|
TableFieldExtraRow,
|
||||||
type TableFieldRowProps
|
type TableFieldRowProps
|
||||||
@@ -490,12 +489,31 @@ function StockItemDefaultMove({
|
|||||||
function moveToDefault(
|
function moveToDefault(
|
||||||
stockItem: any,
|
stockItem: any,
|
||||||
value: StockItemQuantity,
|
value: StockItemQuantity,
|
||||||
refresh: () => void
|
refresh: () => void,
|
||||||
|
options?: {
|
||||||
|
title?: string;
|
||||||
|
onConfirm?: (location: number) => void;
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
|
const location =
|
||||||
|
stockItem.part_detail?.default_location ??
|
||||||
|
stockItem.part_detail?.category_default_location;
|
||||||
|
|
||||||
modals.openConfirmModal({
|
modals.openConfirmModal({
|
||||||
title: <StylishText>{t`Confirm Stock Transfer`}</StylishText>,
|
title: (
|
||||||
|
<StylishText>{options?.title ?? t`Confirm Stock Transfer`}</StylishText>
|
||||||
|
),
|
||||||
children: <StockItemDefaultMove stockItem={stockItem} value={value} />,
|
children: <StockItemDefaultMove stockItem={stockItem} value={value} />,
|
||||||
onConfirm: () => {
|
onConfirm: () => {
|
||||||
|
if (!location) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.onConfirm) {
|
||||||
|
options.onConfirm(location);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
stockItem.location === stockItem.part_detail?.default_location ||
|
stockItem.location === stockItem.part_detail?.default_location ||
|
||||||
stockItem.location === stockItem.part_detail?.category_default_location
|
stockItem.location === stockItem.part_detail?.category_default_location
|
||||||
@@ -512,9 +530,7 @@ function moveToDefault(
|
|||||||
status: stockItem.status
|
status: stockItem.status
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
location:
|
location: location
|
||||||
stockItem.part_detail?.default_location ??
|
|
||||||
stockItem.part_detail?.category_default_location
|
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
refresh();
|
refresh();
|
||||||
@@ -548,6 +564,7 @@ function StockOperationsRow({
|
|||||||
add = false,
|
add = false,
|
||||||
setMax = false,
|
setMax = false,
|
||||||
merge = false,
|
merge = false,
|
||||||
|
returnStock = false,
|
||||||
record
|
record
|
||||||
}: {
|
}: {
|
||||||
props: TableFieldRowProps;
|
props: TableFieldRowProps;
|
||||||
@@ -556,8 +573,11 @@ function StockOperationsRow({
|
|||||||
add?: boolean;
|
add?: boolean;
|
||||||
setMax?: boolean;
|
setMax?: boolean;
|
||||||
merge?: boolean;
|
merge?: boolean;
|
||||||
|
returnStock?: boolean;
|
||||||
record?: any;
|
record?: any;
|
||||||
}) {
|
}) {
|
||||||
|
const form = useFormContext();
|
||||||
|
|
||||||
const statusOptions: ApiFormFieldChoice[] = useMemo(() => {
|
const statusOptions: ApiFormFieldChoice[] = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
StatusFilterOptions(ModelType.stockitem)()?.map((choice) => {
|
StatusFilterOptions(ModelType.stockitem)()?.map((choice) => {
|
||||||
@@ -676,7 +696,22 @@ function StockOperationsRow({
|
|||||||
{transfer && (
|
{transfer && (
|
||||||
<ActionButton
|
<ActionButton
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
moveToDefault(record, props.item.quantity, removeAndRefresh)
|
moveToDefault(
|
||||||
|
record,
|
||||||
|
props.item.quantity,
|
||||||
|
removeAndRefresh,
|
||||||
|
returnStock
|
||||||
|
? {
|
||||||
|
title: t`Confirm Stock Return`,
|
||||||
|
onConfirm: (location: number) => {
|
||||||
|
form.setValue('location', location, {
|
||||||
|
shouldDirty: true,
|
||||||
|
shouldValidate: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
}
|
}
|
||||||
icon={<InvenTreeIcon icon='default_location' />}
|
icon={<InvenTreeIcon icon='default_location' />}
|
||||||
tooltip={t`Move to default location`}
|
tooltip={t`Move to default location`}
|
||||||
@@ -840,6 +875,7 @@ function stockReturnFields(items: any[]): ApiFormFieldSet {
|
|||||||
key={record.pk}
|
key={record.pk}
|
||||||
record={record}
|
record={record}
|
||||||
transfer
|
transfer
|
||||||
|
returnStock
|
||||||
changeStatus
|
changeStatus
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -854,12 +890,25 @@ function stockReturnFields(items: any[]): ApiFormFieldSet {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
location: {
|
location: {
|
||||||
|
field_type: 'related field',
|
||||||
|
api_url: apiUrl(ApiEndpoints.stock_location_list),
|
||||||
|
model: ModelType.stocklocation,
|
||||||
|
required: true,
|
||||||
filters: {
|
filters: {
|
||||||
structural: false
|
structural: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
merge: {},
|
merge: {
|
||||||
notes: {}
|
field_type: 'boolean',
|
||||||
|
label: t`Merge into existing stock`,
|
||||||
|
description: t`Merge returned items into existing stock items if possible`,
|
||||||
|
value: false
|
||||||
|
},
|
||||||
|
notes: {
|
||||||
|
field_type: 'string',
|
||||||
|
label: t`Notes`,
|
||||||
|
description: t`Stock transaction notes`
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
@@ -1593,11 +1642,7 @@ export function useTestResultFields({
|
|||||||
/**
|
/**
|
||||||
* Modal form for finding a particular stock item by serial number
|
* Modal form for finding a particular stock item by serial number
|
||||||
*/
|
*/
|
||||||
export function useFindSerialNumberForm({
|
export function useFindSerialNumberForm({ partId }: { partId: number }) {
|
||||||
partId
|
|
||||||
}: {
|
|
||||||
partId: number;
|
|
||||||
}) {
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return useApiFormModal({
|
return useApiFormModal({
|
||||||
|
|||||||
Reference in New Issue
Block a user