mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-14 08:19:54 +00:00
Obvserve default values for part forms (#10964)
- Closes https://github.com/inventree/InvenTree/issues/10909 - Use global setting values as defaults
This commit is contained in:
@@ -16,8 +16,12 @@ export function usePartFields({
|
|||||||
}): ApiFormFieldSet {
|
}): ApiFormFieldSet {
|
||||||
const settings = useGlobalSettingsState();
|
const settings = useGlobalSettingsState();
|
||||||
|
|
||||||
const [virtual, setVirtual] = useState<boolean>(false);
|
const globalSettings = useGlobalSettingsState();
|
||||||
const [purchaseable, setPurchaseable] = useState<boolean>(false);
|
|
||||||
|
const [virtual, setVirtual] = useState<boolean | undefined>(undefined);
|
||||||
|
const [purchaseable, setPurchaseable] = useState<boolean | undefined>(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const fields: ApiFormFieldSet = {
|
const fields: ApiFormFieldSet = {
|
||||||
@@ -56,19 +60,33 @@ export function usePartFields({
|
|||||||
is_active: true
|
is_active: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
component: {},
|
component: {
|
||||||
assembly: {},
|
default: globalSettings.isSet('PART_COMPONENT')
|
||||||
is_template: {},
|
},
|
||||||
testable: {},
|
assembly: {
|
||||||
trackable: {},
|
default: globalSettings.isSet('PART_ASSEMBLY')
|
||||||
|
},
|
||||||
|
is_template: {
|
||||||
|
default: globalSettings.isSet('PART_TEMPLATE')
|
||||||
|
},
|
||||||
|
testable: {
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
trackable: {
|
||||||
|
default: globalSettings.isSet('PART_TRACKABLE')
|
||||||
|
},
|
||||||
purchaseable: {
|
purchaseable: {
|
||||||
value: purchaseable,
|
value: purchaseable,
|
||||||
|
default: globalSettings.isSet('PART_PURCHASEABLE'),
|
||||||
onValueChange: (value: boolean) => {
|
onValueChange: (value: boolean) => {
|
||||||
setPurchaseable(value);
|
setPurchaseable(value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
salable: {},
|
salable: {
|
||||||
|
default: globalSettings.isSet('PART_SALABLE')
|
||||||
|
},
|
||||||
virtual: {
|
virtual: {
|
||||||
|
default: globalSettings.isSet('PART_VIRTUAL'),
|
||||||
value: virtual,
|
value: virtual,
|
||||||
onValueChange: (value: boolean) => {
|
onValueChange: (value: boolean) => {
|
||||||
setVirtual(value);
|
setVirtual(value);
|
||||||
@@ -89,7 +107,7 @@ export function usePartFields({
|
|||||||
if (create) {
|
if (create) {
|
||||||
fields.copy_category_parameters = {};
|
fields.copy_category_parameters = {};
|
||||||
|
|
||||||
if (!virtual) {
|
if (virtual != false) {
|
||||||
fields.initial_stock = {
|
fields.initial_stock = {
|
||||||
icon: <IconPackages />,
|
icon: <IconPackages />,
|
||||||
children: {
|
children: {
|
||||||
@@ -172,7 +190,14 @@ export function usePartFields({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}, [virtual, purchaseable, create, duplicatePartInstance, settings]);
|
}, [
|
||||||
|
virtual,
|
||||||
|
purchaseable,
|
||||||
|
create,
|
||||||
|
globalSettings,
|
||||||
|
duplicatePartInstance,
|
||||||
|
settings
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user