From afc1dad8a76fe781c570c000302b4fe85a14cc4f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 6 Dec 2025 20:28:22 +1100 Subject: [PATCH] Obvserve default values for part forms (#10964) (#10965) - Closes https://github.com/inventree/InvenTree/issues/10909 - Use global setting values as defaults (cherry picked from commit 3a18934b83aa02d6ee6d0677a095b3d28e530ff8) Co-authored-by: Oliver --- src/frontend/src/forms/PartForms.tsx | 45 +++++++++++++++++++++------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/forms/PartForms.tsx b/src/frontend/src/forms/PartForms.tsx index 4125d00788..656a24e566 100644 --- a/src/frontend/src/forms/PartForms.tsx +++ b/src/frontend/src/forms/PartForms.tsx @@ -20,8 +20,12 @@ export function usePartFields({ }): ApiFormFieldSet { const settings = useGlobalSettingsState(); - const [virtual, setVirtual] = useState(false); - const [purchaseable, setPurchaseable] = useState(false); + const globalSettings = useGlobalSettingsState(); + + const [virtual, setVirtual] = useState(undefined); + const [purchaseable, setPurchaseable] = useState( + undefined + ); return useMemo(() => { const fields: ApiFormFieldSet = { @@ -60,19 +64,33 @@ export function usePartFields({ is_active: true } }, - component: {}, - assembly: {}, - is_template: {}, - testable: {}, - trackable: {}, + component: { + default: globalSettings.isSet('PART_COMPONENT') + }, + assembly: { + default: globalSettings.isSet('PART_ASSEMBLY') + }, + is_template: { + default: globalSettings.isSet('PART_TEMPLATE') + }, + testable: { + default: false + }, + trackable: { + default: globalSettings.isSet('PART_TRACKABLE') + }, purchaseable: { value: purchaseable, + default: globalSettings.isSet('PART_PURCHASEABLE'), onValueChange: (value: boolean) => { setPurchaseable(value); } }, - salable: {}, + salable: { + default: globalSettings.isSet('PART_SALABLE') + }, virtual: { + default: globalSettings.isSet('PART_VIRTUAL'), value: virtual, onValueChange: (value: boolean) => { setVirtual(value); @@ -93,7 +111,7 @@ export function usePartFields({ if (create) { fields.copy_category_parameters = {}; - if (!virtual) { + if (virtual != false) { fields.initial_stock = { icon: , children: { @@ -176,7 +194,14 @@ export function usePartFields({ } return fields; - }, [virtual, purchaseable, create, duplicatePartInstance, settings]); + }, [ + virtual, + purchaseable, + create, + globalSettings, + duplicatePartInstance, + settings + ]); } /**