mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Reintroduce setting for project codes (#8920)
* Re-introducde old setting * Optionally hide project code column * Control visibility of table filters * Hide fields from forms
This commit is contained in:
parent
37c8418f0e
commit
87ccf52562
@ -1003,6 +1003,12 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
|
|||||||
'validator': bool,
|
'validator': bool,
|
||||||
'after_save': reload_plugin_registry,
|
'after_save': reload_plugin_registry,
|
||||||
},
|
},
|
||||||
|
'PROJECT_CODES_ENABLED': {
|
||||||
|
'name': _('Enable project codes'),
|
||||||
|
'description': _('Enable project codes for tracking projects'),
|
||||||
|
'default': False,
|
||||||
|
'validator': bool,
|
||||||
|
},
|
||||||
'STOCKTAKE_ENABLE': {
|
'STOCKTAKE_ENABLE': {
|
||||||
'name': _('Stocktake Functionality'),
|
'name': _('Stocktake Functionality'),
|
||||||
'description': _(
|
'description': _(
|
||||||
|
@ -132,6 +132,10 @@ export function useBuildOrderFields({
|
|||||||
fields.create_child_builds = {};
|
fields.create_child_builds = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||||
|
delete fields.project_code;
|
||||||
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}, [create, destination, batchCode, globalSettings]);
|
}, [create, destination, batchCode, globalSettings]);
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,8 @@ export function usePurchaseOrderFields({
|
|||||||
supplierId?: number;
|
supplierId?: number;
|
||||||
duplicateOrderId?: number;
|
duplicateOrderId?: number;
|
||||||
}): ApiFormFieldSet {
|
}): ApiFormFieldSet {
|
||||||
|
const globalSettings = useGlobalSettingsState();
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const fields: ApiFormFieldSet = {
|
const fields: ApiFormFieldSet = {
|
||||||
reference: {
|
reference: {
|
||||||
@ -217,8 +219,12 @@ export function usePurchaseOrderFields({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||||
|
delete fields.project_code;
|
||||||
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}, [duplicateOrderId, supplierId]);
|
}, [duplicateOrderId, supplierId, globalSettings]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import { ApiEndpoints } from '../enums/ApiEndpoints';
|
|||||||
import { ModelType } from '../enums/ModelType';
|
import { ModelType } from '../enums/ModelType';
|
||||||
import { useCreateApiFormModal } from '../hooks/UseForm';
|
import { useCreateApiFormModal } from '../hooks/UseForm';
|
||||||
import { apiUrl } from '../states/ApiState';
|
import { apiUrl } from '../states/ApiState';
|
||||||
|
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||||
import { StatusFilterOptions } from '../tables/Filter';
|
import { StatusFilterOptions } from '../tables/Filter';
|
||||||
|
|
||||||
export function useReturnOrderFields({
|
export function useReturnOrderFields({
|
||||||
@ -22,6 +23,8 @@ export function useReturnOrderFields({
|
|||||||
}: {
|
}: {
|
||||||
duplicateOrderId?: number;
|
duplicateOrderId?: number;
|
||||||
}): ApiFormFieldSet {
|
}): ApiFormFieldSet {
|
||||||
|
const globalSettings = useGlobalSettingsState();
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const fields: ApiFormFieldSet = {
|
const fields: ApiFormFieldSet = {
|
||||||
reference: {},
|
reference: {},
|
||||||
@ -82,8 +85,12 @@ export function useReturnOrderFields({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||||
|
delete fields.project_code;
|
||||||
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}, [duplicateOrderId]);
|
}, [duplicateOrderId, globalSettings]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useReturnOrderLineItemFields({
|
export function useReturnOrderLineItemFields({
|
||||||
|
@ -16,6 +16,7 @@ import { ApiEndpoints } from '../enums/ApiEndpoints';
|
|||||||
import { ModelType } from '../enums/ModelType';
|
import { ModelType } from '../enums/ModelType';
|
||||||
import { useCreateApiFormModal } from '../hooks/UseForm';
|
import { useCreateApiFormModal } from '../hooks/UseForm';
|
||||||
import { apiUrl } from '../states/ApiState';
|
import { apiUrl } from '../states/ApiState';
|
||||||
|
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||||
import { PartColumn } from '../tables/ColumnRenderers';
|
import { PartColumn } from '../tables/ColumnRenderers';
|
||||||
|
|
||||||
export function useSalesOrderFields({
|
export function useSalesOrderFields({
|
||||||
@ -23,6 +24,8 @@ export function useSalesOrderFields({
|
|||||||
}: {
|
}: {
|
||||||
duplicateOrderId?: number;
|
duplicateOrderId?: number;
|
||||||
}): ApiFormFieldSet {
|
}): ApiFormFieldSet {
|
||||||
|
const globalSettings = useGlobalSettingsState();
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const fields: ApiFormFieldSet = {
|
const fields: ApiFormFieldSet = {
|
||||||
reference: {},
|
reference: {},
|
||||||
@ -76,8 +79,12 @@ export function useSalesOrderFields({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||||
|
delete fields.project_code;
|
||||||
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}, [duplicateOrderId]);
|
}, [duplicateOrderId, globalSettings]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSalesOrderLineItemFields({
|
export function useSalesOrderLineItemFields({
|
||||||
|
@ -26,6 +26,7 @@ import PageTitle from '../../../../components/nav/PageTitle';
|
|||||||
import { SettingsHeader } from '../../../../components/nav/SettingsHeader';
|
import { SettingsHeader } from '../../../../components/nav/SettingsHeader';
|
||||||
import type { PanelType } from '../../../../components/panels/Panel';
|
import type { PanelType } from '../../../../components/panels/Panel';
|
||||||
import { PanelGroup } from '../../../../components/panels/PanelGroup';
|
import { PanelGroup } from '../../../../components/panels/PanelGroup';
|
||||||
|
import { GlobalSettingList } from '../../../../components/settings/SettingList';
|
||||||
import { Loadable } from '../../../../functions/loading';
|
import { Loadable } from '../../../../functions/loading';
|
||||||
import { useUserState } from '../../../../states/UserState';
|
import { useUserState } from '../../../../states/UserState';
|
||||||
|
|
||||||
@ -144,6 +145,7 @@ export default function AdminCenter() {
|
|||||||
icon: <IconListDetails />,
|
icon: <IconListDetails />,
|
||||||
content: (
|
content: (
|
||||||
<Stack gap='xs'>
|
<Stack gap='xs'>
|
||||||
|
<GlobalSettingList keys={['PROJECT_CODES_ENABLED']} />
|
||||||
<ProjectCodeTable />
|
<ProjectCodeTable />
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
)
|
||||||
|
@ -14,6 +14,7 @@ import { formatCurrency, formatDate } from '../defaults/formatters';
|
|||||||
import type { ModelType } from '../enums/ModelType';
|
import type { ModelType } from '../enums/ModelType';
|
||||||
import { resolveItem } from '../functions/conversion';
|
import { resolveItem } from '../functions/conversion';
|
||||||
import { cancelEvent } from '../functions/events';
|
import { cancelEvent } from '../functions/events';
|
||||||
|
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||||
import type { TableColumn, TableColumnProps } from './Column';
|
import type { TableColumn, TableColumnProps } from './Column';
|
||||||
import { ProjectCodeHoverCard } from './TableHoverCard';
|
import { ProjectCodeHoverCard } from './TableHoverCard';
|
||||||
|
|
||||||
@ -161,11 +162,15 @@ export function LineItemsProgressColumn(): TableColumn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ProjectCodeColumn(props: TableColumnProps): TableColumn {
|
export function ProjectCodeColumn(props: TableColumnProps): TableColumn {
|
||||||
|
const globalSettings = useGlobalSettingsState.getState();
|
||||||
|
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accessor: 'project_code',
|
accessor: 'project_code',
|
||||||
ordering: 'project_code',
|
ordering: 'project_code',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
title: t`Project Code`,
|
title: t`Project Code`,
|
||||||
|
hidden: !enabled,
|
||||||
render: (record: any) => {
|
render: (record: any) => {
|
||||||
const project_code = resolveItem(
|
const project_code = resolveItem(
|
||||||
record,
|
record,
|
||||||
|
@ -5,6 +5,7 @@ import type {
|
|||||||
StatusCodeListInterface
|
StatusCodeListInterface
|
||||||
} from '../components/render/StatusRenderer';
|
} from '../components/render/StatusRenderer';
|
||||||
import type { ModelType } from '../enums/ModelType';
|
import type { ModelType } from '../enums/ModelType';
|
||||||
|
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||||
import { type StatusLookup, useGlobalStatusState } from '../states/StatusState';
|
import { type StatusLookup, useGlobalStatusState } from '../states/StatusState';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,9 +29,16 @@ export type TableFilterType = 'boolean' | 'choice' | 'date' | 'text';
|
|||||||
/**
|
/**
|
||||||
* Interface for the table filter type. Provides a number of options for selecting filter value:
|
* Interface for the table filter type. Provides a number of options for selecting filter value:
|
||||||
*
|
*
|
||||||
|
* name: The name of the filter (used for query string)
|
||||||
|
* label: The label to display in the UI (human readable)
|
||||||
|
* description: A description of the filter (human readable)
|
||||||
|
* type: The type of filter (see TableFilterType)
|
||||||
* choices: A list of TableFilterChoice objects
|
* choices: A list of TableFilterChoice objects
|
||||||
* choiceFunction: A function which returns a list of TableFilterChoice objects
|
* choiceFunction: A function which returns a list of TableFilterChoice objects
|
||||||
* statusType: A ModelType which is used to generate a list of status codes
|
* defaultValue: The default value for the filter
|
||||||
|
* value: The current value of the filter
|
||||||
|
* displayValue: The current display value of the filter
|
||||||
|
* active: Whether the filter is active (false = hidden, not used)
|
||||||
*/
|
*/
|
||||||
export type TableFilter = {
|
export type TableFilter = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -198,11 +206,15 @@ export function CompletedAfterFilter(): TableFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function HasProjectCodeFilter(): TableFilter {
|
export function HasProjectCodeFilter(): TableFilter {
|
||||||
|
const globalSettings = useGlobalSettingsState.getState();
|
||||||
|
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'has_project_code',
|
name: 'has_project_code',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
label: t`Has Project Code`,
|
label: t`Has Project Code`,
|
||||||
description: t`Show orders with an assigned project code`
|
description: t`Show orders with an assigned project code`,
|
||||||
|
active: enabled
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,10 +232,14 @@ export function OrderStatusFilter({
|
|||||||
export function ProjectCodeFilter({
|
export function ProjectCodeFilter({
|
||||||
choices
|
choices
|
||||||
}: { choices: TableFilterChoice[] }): TableFilter {
|
}: { choices: TableFilterChoice[] }): TableFilter {
|
||||||
|
const globalSettings = useGlobalSettingsState.getState();
|
||||||
|
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'project_code',
|
name: 'project_code',
|
||||||
label: t`Project Code`,
|
label: t`Project Code`,
|
||||||
description: t`Filter by project code`,
|
description: t`Filter by project code`,
|
||||||
|
active: enabled,
|
||||||
choices: choices
|
choices: choices
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user