mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-20 03:03:30 +00:00
- Closes https://github.com/inventree/InvenTree/issues/10909
- Use global setting values as defaults
(cherry picked from commit 3a18934b83)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
committed by
GitHub
parent
66b71c1f2e
commit
afc1dad8a7
@@ -20,8 +20,12 @@ export function usePartFields({
|
||||
}): ApiFormFieldSet {
|
||||
const settings = useGlobalSettingsState();
|
||||
|
||||
const [virtual, setVirtual] = useState<boolean>(false);
|
||||
const [purchaseable, setPurchaseable] = useState<boolean>(false);
|
||||
const globalSettings = useGlobalSettingsState();
|
||||
|
||||
const [virtual, setVirtual] = useState<boolean | undefined>(undefined);
|
||||
const [purchaseable, setPurchaseable] = useState<boolean | undefined>(
|
||||
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: <IconPackages />,
|
||||
children: {
|
||||
@@ -176,7 +194,14 @@ export function usePartFields({
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [virtual, purchaseable, create, duplicatePartInstance, settings]);
|
||||
}, [
|
||||
virtual,
|
||||
purchaseable,
|
||||
create,
|
||||
globalSettings,
|
||||
duplicatePartInstance,
|
||||
settings
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user