2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-11-14 03:46:44 +00:00

[UI] Auto-fill stock allocation for build order (#10819)

* Auto-fill stock allocation for build order

* Auto-fill allocation for sales orders

* Prevent recursive auto-fills
This commit is contained in:
Oliver
2025-11-13 23:16:32 +11:00
committed by GitHub
parent af6cce3aba
commit 0790dfff5b
4 changed files with 18 additions and 2 deletions

View File

@@ -62,6 +62,13 @@ export function RelatedModelField({
const [isOpen, setIsOpen] = useState<boolean>(false); const [isOpen, setIsOpen] = useState<boolean>(false);
const [autoFilled, setAutoFilled] = useState<boolean>(false);
useEffect(() => {
// Reset auto-fill status when the form is reconstructed
setAutoFilled(false);
}, []);
// Auto-fill the field with data from the API // Auto-fill the field with data from the API
useEffect(() => { useEffect(() => {
// If there is *no value defined*, and autoFill is enabled, then fetch data from the API // If there is *no value defined*, and autoFill is enabled, then fetch data from the API
@@ -69,10 +76,17 @@ export function RelatedModelField({
return; return;
} }
// Return if the autofill has already been performed
if (autoFilled) {
return;
}
if (field.value != undefined) { if (field.value != undefined) {
return; return;
} }
setAutoFilled(true);
// Construct parameters for auto-filling the field // Construct parameters for auto-filling the field
const params = { const params = {
...(definition?.filters ?? {}), ...(definition?.filters ?? {}),
@@ -114,6 +128,7 @@ export function RelatedModelField({
} }
}); });
}, [ }, [
autoFilled,
definition.autoFill, definition.autoFill,
definition.api_url, definition.api_url,
definition.filters, definition.filters,

View File

@@ -215,7 +215,7 @@ export function RenderInlineModel({
return ( return (
<Group gap='xs' justify='space-between' title={tooltip}> <Group gap='xs' justify='space-between' title={tooltip}>
<Group gap='xs' justify='left' wrap='nowrap'> <Group gap='xs' justify='left'>
{prefix} {prefix}
{image && <Thumbnail src={image} size={18} />} {image && <Thumbnail src={image} size={18} />}
{url ? ( {url ? (

View File

@@ -517,7 +517,7 @@ function BuildAllocateLineRow({
field_type: 'related field', field_type: 'related field',
api_url: apiUrl(ApiEndpoints.stock_item_list), api_url: apiUrl(ApiEndpoints.stock_item_list),
model: ModelType.stockitem, model: ModelType.stockitem,
autoFill: !!output?.serial, autoFill: !output || !!output?.serial,
autoFillFilters: { autoFillFilters: {
serial: output?.serial serial: output?.serial
}, },

View File

@@ -184,6 +184,7 @@ function SalesOrderAllocateLineRow({
field_type: 'related field', field_type: 'related field',
api_url: apiUrl(ApiEndpoints.stock_item_list), api_url: apiUrl(ApiEndpoints.stock_item_list),
model: ModelType.stockitem, model: ModelType.stockitem,
autoFill: true,
filters: { filters: {
available: true, available: true,
part_detail: true, part_detail: true,