Internal company support (#13017)

* Add internal company flag

* Unit tests

* Add changelog entry and update API version

* add global company table

* Expose model_filters for internal settings

* Update API version

* Update CHANGELOG

* update assert

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
OliverandMatthias Mair authored and GitHub committed 2026-10-15 11:20:59 +11:00
1 parent 720ba157bb
commit 9b8fdeb06d
22 files changed
+337 -6

No files matched your search

+1
View File
@@ -189,6 +189,7 @@ export function companyFields({
is_supplier: {},
is_manufacturer: {},
is_customer: {},
is_internal: {},
active: {},
duplicate: DuplicateField({
originalId: duplicateCompanyId,
+2
View File
@@ -10,6 +10,7 @@ import {
IconBrandTelegram,
IconBuilding,
IconBuildingFactory2,
IconBuildingSkyscraper,
IconBuildingStore,
IconBusinessplan,
IconCalendar,
@@ -158,6 +159,7 @@ const icons: InvenTreeIconType = {
manufacturers: IconBuildingFactory2,
suppliers: IconBuilding,
customers: IconBuildingStore,
internal_company: IconBuildingSkyscraper,
purchase_orders: IconShoppingCart,
return_orders: IconTruckReturn,
transfer_orders: IconTransfer,
@@ -4,6 +4,7 @@ import type { PanelGroupType, PanelType } from '@lib/types/Panel';
import { t } from '@lingui/core/macro';
import { Stack } from '@mantine/core';
import {
IconBuilding,
IconCoins,
IconCpu,
IconDevicesPc,
@@ -35,6 +36,7 @@ import { PanelGroup } from '../../../../components/panels/PanelGroup';
import { GlobalSettingList } from '../../../../components/settings/SettingList';
import { Loadable } from '../../../../functions/loading';
import { useUserState } from '../../../../states/UserState';
import { CompanyTable } from '../../../../tables/company/CompanyTable';
import ParameterTemplateTable from '../../../../tables/general/ParameterTemplateTable';
import SelectionListTable from '../../../../tables/settings/SelectionListTable';
@@ -176,6 +178,17 @@ export default function AdminCenter() {
icon: <IconExclamationCircle />,
content: <ErrorReportTable />
},
{
name: 'companies',
label: t`Companies`,
icon: <IconBuilding />,
content: (
<Stack gap='xs'>
<GlobalSettingList keys={['INVENTREE_DEFAULT_INTERNAL_COMPANY']} />
<CompanyTable companyType='all' />
</Stack>
)
},
{
name: 'currencies',
label: t`Currencies`,
@@ -299,6 +312,7 @@ export default function AdminCenter() {
'barcode-history',
'background',
'errors',
'companies',
'currencies',
'email'
]
@@ -47,6 +47,7 @@ export default function SystemSettings() {
keys={[
'INVENTREE_BASE_URL',
'INVENTREE_COMPANY_NAME',
'INVENTREE_DEFAULT_INTERNAL_COMPANY',
'INVENTREE_INSTANCE',
'INVENTREE_INSTANCE_TITLE',
'INVENTREE_INSTANCE_ID',
@@ -83,6 +83,13 @@ export function CompanyDetailsPanel({
name: 'is_customer',
label: t`Customer`,
icon: 'customers'
},
{
type: 'boolean',
name: 'is_internal',
label: t`Internal`,
icon: 'internal_company',
hidden: !instance?.is_internal
}
];
@@ -27,6 +27,13 @@ import { usePreviewDrawerState } from '../../states/PreviewDrawerState';
import { useUserSettingsState } from '../../states/SettingsStates';
import { useUserState } from '../../states/UserState';
type CompanyTableType =
| 'all'
| 'internal'
| 'supplier'
| 'manufacturer'
| 'customer';
/**
* A table which displays a list of company records,
* based on the provided filter parameters
@@ -34,10 +41,12 @@ import { useUserState } from '../../states/UserState';
export function CompanyTable({
companyType,
params,
initialData,
path
}: Readonly<{
companyType?: string;
companyType?: CompanyTableType;
params?: any;
initialData?: any;
path?: string;
}>) {
const table = useTable(`company-${companyType ?? 'index'}`, {
@@ -77,18 +86,54 @@ export function CompanyTable({
sortable: true,
switchable: true
}),
BooleanColumn({
accessor: 'is_supplier',
filter: 'is_supplier',
title: t`Supplier`,
sortable: true,
switchable: true,
hidden: companyType === 'supplier',
defaultVisible: false
}),
BooleanColumn({
accessor: 'is_manufacturer',
filter: 'is_manufacturer',
title: t`Manufacturer`,
sortable: true,
switchable: true,
hidden: companyType === 'manufacturer',
defaultVisible: false
}),
BooleanColumn({
accessor: 'is_customer',
filter: 'is_customer',
title: t`Customer`,
sortable: true,
switchable: true,
hidden: companyType === 'customer',
defaultVisible: false
}),
BooleanColumn({
accessor: 'is_internal',
filter: 'is_internal',
title: t`Internal`,
sortable: true,
switchable: true,
hidden: companyType === 'internal',
defaultVisible: false
}),
{
accessor: 'website',
sortable: false
}
];
}, []);
}, [companyType]);
const newCompany = useCreateApiFormModal({
url: ApiEndpoints.company_list,
title: t`Add Company`,
fields: companyFields(),
initialData: params,
initialData: initialData ?? params,
follow: true,
modelType: ModelType.company,
keepOpenOption: true
@@ -126,6 +171,11 @@ export function CompanyTable({
label: t`Customer`,
description: t`Show companies which are customers`
},
{
name: 'is_internal',
label: t`Internal`,
description: t`Show companies which represent your own organization`
},
TagsFilter({ modelType: ModelType.company })
];
}, []);