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,
|
||||
'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': {
|
||||
'name': _('Stocktake Functionality'),
|
||||
'description': _(
|
||||
|
@ -132,6 +132,10 @@ export function useBuildOrderFields({
|
||||
fields.create_child_builds = {};
|
||||
}
|
||||
|
||||
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||
delete fields.project_code;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [create, destination, batchCode, globalSettings]);
|
||||
}
|
||||
|
@ -147,6 +147,8 @@ export function usePurchaseOrderFields({
|
||||
supplierId?: number;
|
||||
duplicateOrderId?: number;
|
||||
}): ApiFormFieldSet {
|
||||
const globalSettings = useGlobalSettingsState();
|
||||
|
||||
return useMemo(() => {
|
||||
const fields: ApiFormFieldSet = {
|
||||
reference: {
|
||||
@ -217,8 +219,12 @@ export function usePurchaseOrderFields({
|
||||
};
|
||||
}
|
||||
|
||||
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||
delete fields.project_code;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [duplicateOrderId, supplierId]);
|
||||
}, [duplicateOrderId, supplierId, globalSettings]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ import { ApiEndpoints } from '../enums/ApiEndpoints';
|
||||
import { ModelType } from '../enums/ModelType';
|
||||
import { useCreateApiFormModal } from '../hooks/UseForm';
|
||||
import { apiUrl } from '../states/ApiState';
|
||||
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||
import { StatusFilterOptions } from '../tables/Filter';
|
||||
|
||||
export function useReturnOrderFields({
|
||||
@ -22,6 +23,8 @@ export function useReturnOrderFields({
|
||||
}: {
|
||||
duplicateOrderId?: number;
|
||||
}): ApiFormFieldSet {
|
||||
const globalSettings = useGlobalSettingsState();
|
||||
|
||||
return useMemo(() => {
|
||||
const fields: ApiFormFieldSet = {
|
||||
reference: {},
|
||||
@ -82,8 +85,12 @@ export function useReturnOrderFields({
|
||||
};
|
||||
}
|
||||
|
||||
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||
delete fields.project_code;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [duplicateOrderId]);
|
||||
}, [duplicateOrderId, globalSettings]);
|
||||
}
|
||||
|
||||
export function useReturnOrderLineItemFields({
|
||||
|
@ -16,6 +16,7 @@ import { ApiEndpoints } from '../enums/ApiEndpoints';
|
||||
import { ModelType } from '../enums/ModelType';
|
||||
import { useCreateApiFormModal } from '../hooks/UseForm';
|
||||
import { apiUrl } from '../states/ApiState';
|
||||
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||
import { PartColumn } from '../tables/ColumnRenderers';
|
||||
|
||||
export function useSalesOrderFields({
|
||||
@ -23,6 +24,8 @@ export function useSalesOrderFields({
|
||||
}: {
|
||||
duplicateOrderId?: number;
|
||||
}): ApiFormFieldSet {
|
||||
const globalSettings = useGlobalSettingsState();
|
||||
|
||||
return useMemo(() => {
|
||||
const fields: ApiFormFieldSet = {
|
||||
reference: {},
|
||||
@ -76,8 +79,12 @@ export function useSalesOrderFields({
|
||||
};
|
||||
}
|
||||
|
||||
if (!globalSettings.isSet('PROJECT_CODES_ENABLED', true)) {
|
||||
delete fields.project_code;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [duplicateOrderId]);
|
||||
}, [duplicateOrderId, globalSettings]);
|
||||
}
|
||||
|
||||
export function useSalesOrderLineItemFields({
|
||||
|
@ -26,6 +26,7 @@ import PageTitle from '../../../../components/nav/PageTitle';
|
||||
import { SettingsHeader } from '../../../../components/nav/SettingsHeader';
|
||||
import type { PanelType } from '../../../../components/panels/Panel';
|
||||
import { PanelGroup } from '../../../../components/panels/PanelGroup';
|
||||
import { GlobalSettingList } from '../../../../components/settings/SettingList';
|
||||
import { Loadable } from '../../../../functions/loading';
|
||||
import { useUserState } from '../../../../states/UserState';
|
||||
|
||||
@ -144,6 +145,7 @@ export default function AdminCenter() {
|
||||
icon: <IconListDetails />,
|
||||
content: (
|
||||
<Stack gap='xs'>
|
||||
<GlobalSettingList keys={['PROJECT_CODES_ENABLED']} />
|
||||
<ProjectCodeTable />
|
||||
</Stack>
|
||||
)
|
||||
|
@ -14,6 +14,7 @@ import { formatCurrency, formatDate } from '../defaults/formatters';
|
||||
import type { ModelType } from '../enums/ModelType';
|
||||
import { resolveItem } from '../functions/conversion';
|
||||
import { cancelEvent } from '../functions/events';
|
||||
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||
import type { TableColumn, TableColumnProps } from './Column';
|
||||
import { ProjectCodeHoverCard } from './TableHoverCard';
|
||||
|
||||
@ -161,11 +162,15 @@ export function LineItemsProgressColumn(): TableColumn {
|
||||
}
|
||||
|
||||
export function ProjectCodeColumn(props: TableColumnProps): TableColumn {
|
||||
const globalSettings = useGlobalSettingsState.getState();
|
||||
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);
|
||||
|
||||
return {
|
||||
accessor: 'project_code',
|
||||
ordering: 'project_code',
|
||||
sortable: true,
|
||||
title: t`Project Code`,
|
||||
hidden: !enabled,
|
||||
render: (record: any) => {
|
||||
const project_code = resolveItem(
|
||||
record,
|
||||
|
@ -5,6 +5,7 @@ import type {
|
||||
StatusCodeListInterface
|
||||
} from '../components/render/StatusRenderer';
|
||||
import type { ModelType } from '../enums/ModelType';
|
||||
import { useGlobalSettingsState } from '../states/SettingsState';
|
||||
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:
|
||||
*
|
||||
* 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
|
||||
* 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 = {
|
||||
name: string;
|
||||
@ -198,11 +206,15 @@ export function CompletedAfterFilter(): TableFilter {
|
||||
}
|
||||
|
||||
export function HasProjectCodeFilter(): TableFilter {
|
||||
const globalSettings = useGlobalSettingsState.getState();
|
||||
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);
|
||||
|
||||
return {
|
||||
name: 'has_project_code',
|
||||
type: 'boolean',
|
||||
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({
|
||||
choices
|
||||
}: { choices: TableFilterChoice[] }): TableFilter {
|
||||
const globalSettings = useGlobalSettingsState.getState();
|
||||
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);
|
||||
|
||||
return {
|
||||
name: 'project_code',
|
||||
label: t`Project Code`,
|
||||
description: t`Filter by project code`,
|
||||
active: enabled,
|
||||
choices: choices
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user