From d8cd1849baf112de4de026fba548f72396a36328 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 22 Apr 2026 08:53:31 +0200 Subject: [PATCH] feat(frontend): add inline create modal to PurchaseOrderLineItem dialog (#11778) * feat(frontend): add inline create modal to PurchaseOrderLineItem dialog fixes https://github.com/invenhost/InvenTree/issues/299 * add changelog * implement suggested fix Co-authored-by: Oliver --------- Co-authored-by: Oliver --- CHANGELOG.md | 1 + src/frontend/lib/types/Forms.tsx | 1 + .../forms/fields/RelatedModelField.tsx | 114 ++++++++++++++++-- src/frontend/src/forms/PurchaseOrderForms.tsx | 6 + 4 files changed, 111 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fc1bf862a..2be3883c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [#11778](https://github.com/inventree/InvenTree/pull/11778) adds inline supplier part creation to po line item addition dialog. - [#11772](https://github.com/inventree/InvenTree/pull/11772) the UI now warns if you navigate away from a note panel with unsaved changes ### Changed diff --git a/src/frontend/lib/types/Forms.tsx b/src/frontend/lib/types/Forms.tsx index 2b229dcb45..de364d68f8 100644 --- a/src/frontend/lib/types/Forms.tsx +++ b/src/frontend/lib/types/Forms.tsx @@ -114,6 +114,7 @@ export type ApiFormFieldType = { placeholderAutofill?: boolean; placeholderWarningCompare?: string | number; placeholderWarning?: string; + addCreateFields?: ApiFormFieldSet; description?: string; preFieldContent?: JSX.Element; postFieldContent?: JSX.Element; diff --git a/src/frontend/src/components/forms/fields/RelatedModelField.tsx b/src/frontend/src/components/forms/fields/RelatedModelField.tsx index df711af1c1..d5f0a9fcff 100644 --- a/src/frontend/src/components/forms/fields/RelatedModelField.tsx +++ b/src/frontend/src/components/forms/fields/RelatedModelField.tsx @@ -8,17 +8,32 @@ import { } from '@mantine/core'; import { useDebouncedValue, useId } from '@mantine/hooks'; import { useQuery } from '@tanstack/react-query'; -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { + type ReactNode, + useCallback, + useEffect, + useMemo, + useRef, + useState +} from 'react'; import { type FieldValues, type UseControllerReturn, + type UseFormReturn, useFormContext } from 'react-hook-form'; import Select from 'react-select'; -import { ModelInformationDict } from '@lib/enums/ModelInformation'; +import { ActionButton } from '@lib/components/ActionButton'; +import { + ModelInformationDict, + type TranslatableModelInformationInterface +} from '@lib/enums/ModelInformation'; +import { apiUrl } from '@lib/functions/Api'; import type { ApiFormFieldType } from '@lib/types/Forms'; +import { IconPlus } from '@tabler/icons-react'; import { useApi } from '../../../contexts/ApiContext'; +import { useCreateApiFormModal } from '../../../hooks/UseForm'; import { useGlobalSettingsState, useUserSettingsState @@ -54,6 +69,10 @@ export function RelatedModelField({ // Keep track of the primary key value for this field const [pk, setPk] = useState(null); + function setValuefromPK(pk: number) { + fetchSingleField(pk); + } + // Handle condition where the form is rebuilt dynamically useEffect(() => { const value = field.value || pk; @@ -139,6 +158,17 @@ export function RelatedModelField({ return ModelInformationDict[definition.model]; }, [definition.model]); + // Determine whether an add button should be added for this field + const addButton = useMemo(() => { + if (!modelInfo) { + return false; + } + if (definition.addCreateFields) { + return true; + } + return false; + }, [definition.addCreateFields, modelInfo]); + // Determine whether a barcode field should be added const addBarcodeField: boolean = useMemo(() => { if (!modelInfo || !modelInfo.supports_barcode) { @@ -296,15 +326,7 @@ export function RelatedModelField({ return null; } - let _filters = definition.filters ?? {}; - - if (definition.adjustFilters) { - _filters = - definition.adjustFilters({ - filters: _filters, - data: form.getValues() - }) ?? _filters; - } + const _filters = retrieveFilters(definition, form); // If the filters have changed, clear the data if (JSON.stringify(_filters) !== JSON.stringify(filters)) { @@ -461,6 +483,9 @@ export function RelatedModelField({ styles={{ description: { paddingBottom: '5px' } }} > + {addButton && + modelInfo && + InlineCreateButton(definition, modelInfo, form, setValuefromPK)}