mirror of
https://github.com/inventree/InvenTree.git
synced 2025-11-13 19:36:46 +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:
@@ -62,6 +62,13 @@ export function RelatedModelField({
|
||||
|
||||
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
|
||||
useEffect(() => {
|
||||
// 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 if the autofill has already been performed
|
||||
if (autoFilled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (field.value != undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
setAutoFilled(true);
|
||||
|
||||
// Construct parameters for auto-filling the field
|
||||
const params = {
|
||||
...(definition?.filters ?? {}),
|
||||
@@ -114,6 +128,7 @@ export function RelatedModelField({
|
||||
}
|
||||
});
|
||||
}, [
|
||||
autoFilled,
|
||||
definition.autoFill,
|
||||
definition.api_url,
|
||||
definition.filters,
|
||||
|
||||
@@ -215,7 +215,7 @@ export function RenderInlineModel({
|
||||
|
||||
return (
|
||||
<Group gap='xs' justify='space-between' title={tooltip}>
|
||||
<Group gap='xs' justify='left' wrap='nowrap'>
|
||||
<Group gap='xs' justify='left'>
|
||||
{prefix}
|
||||
{image && <Thumbnail src={image} size={18} />}
|
||||
{url ? (
|
||||
|
||||
@@ -517,7 +517,7 @@ function BuildAllocateLineRow({
|
||||
field_type: 'related field',
|
||||
api_url: apiUrl(ApiEndpoints.stock_item_list),
|
||||
model: ModelType.stockitem,
|
||||
autoFill: !!output?.serial,
|
||||
autoFill: !output || !!output?.serial,
|
||||
autoFillFilters: {
|
||||
serial: output?.serial
|
||||
},
|
||||
|
||||
@@ -184,6 +184,7 @@ function SalesOrderAllocateLineRow({
|
||||
field_type: 'related field',
|
||||
api_url: apiUrl(ApiEndpoints.stock_item_list),
|
||||
model: ModelType.stockitem,
|
||||
autoFill: true,
|
||||
filters: {
|
||||
available: true,
|
||||
part_detail: true,
|
||||
|
||||
Reference in New Issue
Block a user