@inventreedb/ui 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +8 -0
- package/.linguirc +55 -0
- package/README.md +17 -0
- package/index.html +15 -0
- package/lib/enums/ApiEndpoints.tsx +233 -0
- package/lib/enums/ModelType.tsx +38 -0
- package/lib/enums/Roles.tsx +25 -0
- package/lib/functions/Api.tsx +42 -0
- package/lib/functions/Plugins.tsx +27 -0
- package/lib/index.ts +11 -0
- package/lib/types/Auth.tsx +51 -0
- package/lib/types/Core.tsx +13 -0
- package/lib/types/Filters.tsx +69 -0
- package/lib/types/Forms.tsx +185 -0
- package/lib/types/Modals.tsx +17 -0
- package/lib/types/Plugins.tsx +68 -0
- package/lib/types/Server.tsx +8 -0
- package/lib/types/Settings.tsx +55 -0
- package/lib/types/Tables.tsx +69 -0
- package/lib/types/User.tsx +62 -0
- package/netlify.toml +22 -0
- package/package.json +125 -0
- package/playwright/global-setup.ts +45 -0
- package/playwright.config.ts +99 -0
- package/public/inventree.svg +291 -0
- package/src/App.tsx +35 -0
- package/src/assets/inventree.svg +1 -0
- package/src/components/Boundary.tsx +43 -0
- package/src/components/SplashScreen.tsx +35 -0
- package/src/components/barcodes/BarcodeCameraInput.tsx +207 -0
- package/src/components/barcodes/BarcodeInput.tsx +127 -0
- package/src/components/barcodes/BarcodeKeyboardInput.tsx +50 -0
- package/src/components/barcodes/BarcodeScanDialog.tsx +101 -0
- package/src/components/barcodes/BarcodeScanItem.tsx +23 -0
- package/src/components/barcodes/QRCode.tsx +211 -0
- package/src/components/buttons/ActionButton.tsx +61 -0
- package/src/components/buttons/AddItemButton.tsx +10 -0
- package/src/components/buttons/AdminButton.tsx +91 -0
- package/src/components/buttons/ButtonMenu.tsx +33 -0
- package/src/components/buttons/CopyButton.tsx +52 -0
- package/src/components/buttons/PrimaryActionButton.tsx +40 -0
- package/src/components/buttons/PrintingActions.tsx +191 -0
- package/src/components/buttons/RemoveRowButton.tsx +22 -0
- package/src/components/buttons/SSOButton.tsx +53 -0
- package/src/components/buttons/ScanButton.tsx +27 -0
- package/src/components/buttons/SegmentedIconControl.tsx +51 -0
- package/src/components/buttons/SplitButton.css.ts +19 -0
- package/src/components/buttons/SplitButton.tsx +111 -0
- package/src/components/buttons/SpotlightButton.tsx +22 -0
- package/src/components/buttons/StarredToggleButton.tsx +62 -0
- package/src/components/buttons/YesNoButton.tsx +42 -0
- package/src/components/calendar/Calendar.tsx +193 -0
- package/src/components/calendar/OrderCalendar.tsx +209 -0
- package/src/components/charts/colors.tsx +12 -0
- package/src/components/charts/tooltipFormatter.tsx +12 -0
- package/src/components/dashboard/DashboardLayout.tsx +327 -0
- package/src/components/dashboard/DashboardMenu.tsx +136 -0
- package/src/components/dashboard/DashboardWidget.tsx +82 -0
- package/src/components/dashboard/DashboardWidgetDrawer.tsx +130 -0
- package/src/components/dashboard/DashboardWidgetLibrary.tsx +189 -0
- package/src/components/dashboard/widgets/ColorToggleWidget.tsx +28 -0
- package/src/components/dashboard/widgets/GetStartedWidget.tsx +19 -0
- package/src/components/dashboard/widgets/LanguageSelectWidget.tsx +28 -0
- package/src/components/dashboard/widgets/NewsWidget.tsx +143 -0
- package/src/components/dashboard/widgets/QueryCountDashboardWidget.tsx +134 -0
- package/src/components/details/Details.tsx +514 -0
- package/src/components/details/DetailsBadge.tsx +20 -0
- package/src/components/details/DetailsImage.tsx +462 -0
- package/src/components/details/ItemDetails.tsx +17 -0
- package/src/components/editors/NotesEditor.tsx +232 -0
- package/src/components/editors/TemplateEditor/CodeEditor/CodeEditor.tsx +158 -0
- package/src/components/editors/TemplateEditor/CodeEditor/index.tsx +12 -0
- package/src/components/editors/TemplateEditor/PdfPreview/PdfPreview.tsx +90 -0
- package/src/components/editors/TemplateEditor/PdfPreview/index.tsx +12 -0
- package/src/components/editors/TemplateEditor/TemplateEditor.tsx +425 -0
- package/src/components/editors/TemplateEditor/index.tsx +3 -0
- package/src/components/errors/ClientError.tsx +28 -0
- package/src/components/errors/GenericErrorPage.tsx +73 -0
- package/src/components/errors/NotAuthenticated.tsx +12 -0
- package/src/components/errors/NotFound.tsx +12 -0
- package/src/components/errors/PermissionDenied.tsx +12 -0
- package/src/components/errors/ServerError.tsx +13 -0
- package/src/components/forms/ApiForm.tsx +718 -0
- package/src/components/forms/AuthFormOptions.tsx +39 -0
- package/src/components/forms/AuthenticationForm.tsx +332 -0
- package/src/components/forms/HostOptionsForm.tsx +96 -0
- package/src/components/forms/InstanceOptions.tsx +178 -0
- package/src/components/forms/StandaloneField.tsx +55 -0
- package/src/components/forms/fields/ApiFormField.tsx +281 -0
- package/src/components/forms/fields/ChoiceField.tsx +86 -0
- package/src/components/forms/fields/DateField.tsx +79 -0
- package/src/components/forms/fields/DependentField.tsx +91 -0
- package/src/components/forms/fields/IconField.tsx +353 -0
- package/src/components/forms/fields/NestedObjectField.tsx +45 -0
- package/src/components/forms/fields/RelatedModelField.tsx +339 -0
- package/src/components/forms/fields/TableField.tsx +275 -0
- package/src/components/forms/fields/TextField.tsx +81 -0
- package/src/components/images/ApiImage.tsx +35 -0
- package/src/components/images/Thumbnail.tsx +52 -0
- package/src/components/importer/ImportDataSelector.tsx +433 -0
- package/src/components/importer/ImporterColumnSelector.tsx +244 -0
- package/src/components/importer/ImporterDrawer.tsx +173 -0
- package/src/components/importer/ImporterImportProgress.tsx +45 -0
- package/src/components/items/ActionDropdown.tsx +290 -0
- package/src/components/items/ApiIcon.css.ts +13 -0
- package/src/components/items/ApiIcon.tsx +32 -0
- package/src/components/items/AttachmentLink.tsx +79 -0
- package/src/components/items/ColorToggle.tsx +34 -0
- package/src/components/items/DashboardItem.tsx +33 -0
- package/src/components/items/DocInfo.tsx +20 -0
- package/src/components/items/DocTooltip.tsx +98 -0
- package/src/components/items/ErrorItem.tsx +17 -0
- package/src/components/items/Expand.tsx +14 -0
- package/src/components/items/GettingStartedCarousel.css.ts +30 -0
- package/src/components/items/GettingStartedCarousel.tsx +49 -0
- package/src/components/items/InfoItem.tsx +64 -0
- package/src/components/items/InvenTreeLogo.tsx +24 -0
- package/src/components/items/LanguageSelect.tsx +43 -0
- package/src/components/items/LanguageToggle.tsx +37 -0
- package/src/components/items/MenuLinks.tsx +113 -0
- package/src/components/items/OnlyStaff.tsx +10 -0
- package/src/components/items/ProgressBar.tsx +45 -0
- package/src/components/items/StylishText.tsx +59 -0
- package/src/components/items/TitleWithDoc.tsx +26 -0
- package/src/components/items/UnavailableIndicator.tsx +5 -0
- package/src/components/items/inventree.svg +1 -0
- package/src/components/modals/AboutInvenTreeModal.tsx +203 -0
- package/src/components/modals/LicenseModal.tsx +116 -0
- package/src/components/modals/QrModal.tsx +21 -0
- package/src/components/modals/ServerInfoModal.tsx +136 -0
- package/src/components/nav/Alerts.tsx +130 -0
- package/src/components/nav/BreadcrumbList.tsx +84 -0
- package/src/components/nav/DetailDrawer.css.ts +6 -0
- package/src/components/nav/DetailDrawer.tsx +105 -0
- package/src/components/nav/Footer.tsx +11 -0
- package/src/components/nav/Header.tsx +226 -0
- package/src/components/nav/InstanceDetail.tsx +46 -0
- package/src/components/nav/Layout.tsx +85 -0
- package/src/components/nav/MainMenu.tsx +101 -0
- package/src/components/nav/NavHoverMenu.tsx +15 -0
- package/src/components/nav/NavigationDrawer.tsx +230 -0
- package/src/components/nav/NavigationTree.tsx +210 -0
- package/src/components/nav/NotificationDrawer.tsx +231 -0
- package/src/components/nav/PageDetail.tsx +171 -0
- package/src/components/nav/PageTitle.tsx +53 -0
- package/src/components/nav/SearchDrawer.tsx +598 -0
- package/src/components/nav/SettingsHeader.tsx +50 -0
- package/src/components/panels/AttachmentPanel.tsx +27 -0
- package/src/components/panels/NotesPanel.tsx +36 -0
- package/src/components/panels/Panel.tsx +15 -0
- package/src/components/panels/PanelGroup.css.ts +10 -0
- package/src/components/panels/PanelGroup.tsx +292 -0
- package/src/components/plugins/LocateItemButton.tsx +94 -0
- package/src/components/plugins/PluginContext.tsx +67 -0
- package/src/components/plugins/PluginDrawer.tsx +156 -0
- package/src/components/plugins/PluginInterface.tsx +34 -0
- package/src/components/plugins/PluginPanel.tsx +37 -0
- package/src/components/plugins/PluginSettingsPanel.tsx +34 -0
- package/src/components/plugins/PluginSource.tsx +48 -0
- package/src/components/plugins/PluginUIFeature.tsx +174 -0
- package/src/components/plugins/PluginUIFeatureTypes.ts +78 -0
- package/src/components/plugins/RemoteComponent.tsx +137 -0
- package/src/components/render/Build.tsx +54 -0
- package/src/components/render/Company.tsx +114 -0
- package/src/components/render/Generic.tsx +49 -0
- package/src/components/render/Instance.tsx +240 -0
- package/src/components/render/InstanceFromUrl.tsx +33 -0
- package/src/components/render/ModelType.tsx +293 -0
- package/src/components/render/Order.tsx +124 -0
- package/src/components/render/Part.tsx +109 -0
- package/src/components/render/Plugin.tsx +21 -0
- package/src/components/render/Report.tsx +29 -0
- package/src/components/render/StatusRenderer.tsx +178 -0
- package/src/components/render/Stock.tsx +84 -0
- package/src/components/render/User.tsx +42 -0
- package/src/components/settings/FactCollection.tsx +31 -0
- package/src/components/settings/FactItem.tsx +17 -0
- package/src/components/settings/SettingItem.tsx +176 -0
- package/src/components/settings/SettingList.tsx +217 -0
- package/src/components/wizards/OrderPartsWizard.tsx +473 -0
- package/src/components/wizards/WizardDrawer.tsx +188 -0
- package/src/contexts/ApiContext.tsx +31 -0
- package/src/contexts/LanguageContext.tsx +155 -0
- package/src/contexts/ThemeContext.tsx +58 -0
- package/src/contexts/colorSchema.tsx +67 -0
- package/src/defaults/actions.tsx +87 -0
- package/src/defaults/backendMappings.tsx +32 -0
- package/src/defaults/defaultHostList.tsx +4 -0
- package/src/defaults/defaults.tsx +38 -0
- package/src/defaults/formatters.tsx +176 -0
- package/src/defaults/links.tsx +193 -0
- package/src/defaults/templates.tsx +53 -0
- package/src/forms/BomForms.tsx +26 -0
- package/src/forms/BuildForms.tsx +615 -0
- package/src/forms/CommonForms.tsx +89 -0
- package/src/forms/CompanyForms.tsx +133 -0
- package/src/forms/ImporterForms.tsx +20 -0
- package/src/forms/PartForms.tsx +281 -0
- package/src/forms/PurchaseOrderForms.tsx +779 -0
- package/src/forms/ReturnOrderForms.tsx +263 -0
- package/src/forms/SalesOrderForms.tsx +408 -0
- package/src/forms/StockForms.tsx +1296 -0
- package/src/forms/selectionListFields.tsx +120 -0
- package/src/functions/api.tsx +61 -0
- package/src/functions/auth.tsx +574 -0
- package/src/functions/conversion.tsx +42 -0
- package/src/functions/events.tsx +6 -0
- package/src/functions/forms.tsx +173 -0
- package/src/functions/icons.tsx +294 -0
- package/src/functions/loading.tsx +29 -0
- package/src/functions/navigation.tsx +20 -0
- package/src/functions/notifications.tsx +101 -0
- package/src/functions/tables.tsx +26 -0
- package/src/functions/uid.tsx +15 -0
- package/src/functions/urls.tsx +58 -0
- package/src/hooks/UseCalendar.tsx +178 -0
- package/src/hooks/UseDashboardItems.tsx +118 -0
- package/src/hooks/UseDataExport.tsx +125 -0
- package/src/hooks/UseDataOutput.tsx +109 -0
- package/src/hooks/UseFilter.tsx +67 -0
- package/src/hooks/UseFilterSet.tsx +24 -0
- package/src/hooks/UseForm.tsx +161 -0
- package/src/hooks/UseGenerator.tsx +92 -0
- package/src/hooks/UseImportSession.tsx +139 -0
- package/src/hooks/UseInstance.tsx +137 -0
- package/src/hooks/UseInstanceName.tsx +14 -0
- package/src/hooks/UseModal.tsx +38 -0
- package/src/hooks/UsePlaceholder.tsx +66 -0
- package/src/hooks/UsePluginPanels.tsx +123 -0
- package/src/hooks/UsePluginUIFeature.tsx +95 -0
- package/src/hooks/UsePlugins.tsx +45 -0
- package/src/hooks/UseSelectedRows.tsx +37 -0
- package/src/hooks/UseStatusCodes.tsx +50 -0
- package/src/hooks/UseTable.tsx +145 -0
- package/src/hooks/UseWizard.tsx +133 -0
- package/src/locales/ar/messages.d.ts +4 -0
- package/src/locales/ar/messages.po +10695 -0
- package/src/locales/ar/messages.ts +1 -0
- package/src/locales/bg/messages.d.ts +4 -0
- package/src/locales/bg/messages.po +10695 -0
- package/src/locales/bg/messages.ts +1 -0
- package/src/locales/cs/messages.d.ts +4 -0
- package/src/locales/cs/messages.po +10695 -0
- package/src/locales/cs/messages.ts +1 -0
- package/src/locales/da/messages.d.ts +4 -0
- package/src/locales/da/messages.po +10695 -0
- package/src/locales/da/messages.ts +1 -0
- package/src/locales/de/messages.d.ts +4 -0
- package/src/locales/de/messages.po +10695 -0
- package/src/locales/de/messages.ts +1 -0
- package/src/locales/el/messages.d.ts +4 -0
- package/src/locales/el/messages.po +10695 -0
- package/src/locales/el/messages.ts +1 -0
- package/src/locales/en/messages.d.ts +4 -0
- package/src/locales/en/messages.po +10689 -0
- package/src/locales/en/messages.ts +1 -0
- package/src/locales/es/messages.d.ts +4 -0
- package/src/locales/es/messages.po +10695 -0
- package/src/locales/es/messages.ts +1 -0
- package/src/locales/es_MX/messages.d.ts +4 -0
- package/src/locales/es_MX/messages.po +10695 -0
- package/src/locales/es_MX/messages.ts +1 -0
- package/src/locales/et/messages.d.ts +4 -0
- package/src/locales/et/messages.po +10695 -0
- package/src/locales/et/messages.ts +1 -0
- package/src/locales/fa/messages.d.ts +4 -0
- package/src/locales/fa/messages.po +10695 -0
- package/src/locales/fa/messages.ts +1 -0
- package/src/locales/fi/messages.d.ts +4 -0
- package/src/locales/fi/messages.po +10695 -0
- package/src/locales/fi/messages.ts +1 -0
- package/src/locales/fr/messages.d.ts +4 -0
- package/src/locales/fr/messages.po +10695 -0
- package/src/locales/fr/messages.ts +1 -0
- package/src/locales/he/messages.d.ts +4 -0
- package/src/locales/he/messages.po +10695 -0
- package/src/locales/he/messages.ts +1 -0
- package/src/locales/hi/messages.d.ts +4 -0
- package/src/locales/hi/messages.po +10695 -0
- package/src/locales/hi/messages.ts +1 -0
- package/src/locales/hu/messages.d.ts +4 -0
- package/src/locales/hu/messages.po +10695 -0
- package/src/locales/hu/messages.ts +1 -0
- package/src/locales/id/messages.po +10695 -0
- package/src/locales/it/messages.d.ts +4 -0
- package/src/locales/it/messages.po +10695 -0
- package/src/locales/it/messages.ts +1 -0
- package/src/locales/ja/messages.d.ts +4 -0
- package/src/locales/ja/messages.po +10695 -0
- package/src/locales/ja/messages.ts +1 -0
- package/src/locales/ko/messages.d.ts +4 -0
- package/src/locales/ko/messages.po +10695 -0
- package/src/locales/ko/messages.ts +1 -0
- package/src/locales/lt/messages.d.ts +4 -0
- package/src/locales/lt/messages.po +10695 -0
- package/src/locales/lt/messages.ts +1 -0
- package/src/locales/lv/messages.d.ts +4 -0
- package/src/locales/lv/messages.po +10695 -0
- package/src/locales/lv/messages.ts +1 -0
- package/src/locales/nl/messages.d.ts +4 -0
- package/src/locales/nl/messages.po +10695 -0
- package/src/locales/nl/messages.ts +1 -0
- package/src/locales/no/messages.d.ts +4 -0
- package/src/locales/no/messages.po +10695 -0
- package/src/locales/no/messages.ts +1 -0
- package/src/locales/pl/messages.d.ts +4 -0
- package/src/locales/pl/messages.po +10695 -0
- package/src/locales/pl/messages.ts +1 -0
- package/src/locales/pseudo-LOCALE/messages.d.ts +4 -0
- package/src/locales/pseudo-LOCALE/messages.po +8003 -0
- package/src/locales/pseudo-LOCALE/messages.ts +1 -0
- package/src/locales/pt/messages.d.ts +4 -0
- package/src/locales/pt/messages.po +10696 -0
- package/src/locales/pt/messages.ts +1 -0
- package/src/locales/pt_BR/messages.d.ts +4 -0
- package/src/locales/pt_BR/messages.po +10695 -0
- package/src/locales/pt_BR/messages.ts +1 -0
- package/src/locales/ro/messages.po +10695 -0
- package/src/locales/ro/messages.ts +1 -0
- package/src/locales/ru/messages.d.ts +4 -0
- package/src/locales/ru/messages.po +10695 -0
- package/src/locales/ru/messages.ts +1 -0
- package/src/locales/sk/messages.d.ts +4 -0
- package/src/locales/sk/messages.po +10695 -0
- package/src/locales/sk/messages.ts +1 -0
- package/src/locales/sl/messages.d.ts +4 -0
- package/src/locales/sl/messages.po +10695 -0
- package/src/locales/sl/messages.ts +1 -0
- package/src/locales/sr/messages.d.ts +4 -0
- package/src/locales/sr/messages.po +10695 -0
- package/src/locales/sr/messages.ts +1 -0
- package/src/locales/sv/messages.d.ts +4 -0
- package/src/locales/sv/messages.po +10695 -0
- package/src/locales/sv/messages.ts +1 -0
- package/src/locales/th/messages.d.ts +4 -0
- package/src/locales/th/messages.po +10695 -0
- package/src/locales/th/messages.ts +1 -0
- package/src/locales/tr/messages.d.ts +4 -0
- package/src/locales/tr/messages.po +10695 -0
- package/src/locales/tr/messages.ts +1 -0
- package/src/locales/uk/messages.d.ts +3 -0
- package/src/locales/uk/messages.po +10695 -0
- package/src/locales/uk/messages.ts +1 -0
- package/src/locales/vi/messages.d.ts +4 -0
- package/src/locales/vi/messages.po +10695 -0
- package/src/locales/vi/messages.ts +1 -0
- package/src/locales/zh_Hans/messages.d.ts +4 -0
- package/src/locales/zh_Hans/messages.po +10695 -0
- package/src/locales/zh_Hans/messages.ts +1 -0
- package/src/locales/zh_Hant/messages.d.ts +4 -0
- package/src/locales/zh_Hant/messages.po +10695 -0
- package/src/locales/zh_Hant/messages.ts +1 -0
- package/src/main.css.ts +148 -0
- package/src/main.tsx +123 -0
- package/src/pages/Auth/ChangePassword.tsx +84 -0
- package/src/pages/Auth/Layout.tsx +74 -0
- package/src/pages/Auth/LoggedIn.tsx +21 -0
- package/src/pages/Auth/Login.tsx +133 -0
- package/src/pages/Auth/Logout.tsx +16 -0
- package/src/pages/Auth/MFA.tsx +36 -0
- package/src/pages/Auth/MFASetup.tsx +38 -0
- package/src/pages/Auth/Register.tsx +28 -0
- package/src/pages/Auth/Reset.tsx +30 -0
- package/src/pages/Auth/ResetPassword.tsx +48 -0
- package/src/pages/Auth/VerifyEmail.tsx +34 -0
- package/src/pages/ErrorPage.tsx +26 -0
- package/src/pages/Index/Home.tsx +12 -0
- package/src/pages/Index/Scan.tsx +258 -0
- package/src/pages/Index/Settings/AccountSettings/AccountDetailPanel.tsx +162 -0
- package/src/pages/Index/Settings/AccountSettings/QrRegistrationForm.tsx +38 -0
- package/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx +713 -0
- package/src/pages/Index/Settings/AccountSettings/UserPanel.tsx +24 -0
- package/src/pages/Index/Settings/AccountSettings/UserThemePanel.tsx +207 -0
- package/src/pages/Index/Settings/AccountSettings/useConfirm.tsx +117 -0
- package/src/pages/Index/Settings/AdminCenter/CurrencyManagementPanel.tsx +111 -0
- package/src/pages/Index/Settings/AdminCenter/Index.tsx +251 -0
- package/src/pages/Index/Settings/AdminCenter/LabelTemplatePanel.tsx +23 -0
- package/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx +110 -0
- package/src/pages/Index/Settings/AdminCenter/PartParameterPanel.tsx +29 -0
- package/src/pages/Index/Settings/AdminCenter/PluginManagementPanel.tsx +84 -0
- package/src/pages/Index/Settings/AdminCenter/ReportTemplatePanel.tsx +38 -0
- package/src/pages/Index/Settings/AdminCenter/StocktakePanel.tsx +31 -0
- package/src/pages/Index/Settings/AdminCenter/TaskManagementPanel.tsx +73 -0
- package/src/pages/Index/Settings/AdminCenter/UnitManagementPanel.tsx +74 -0
- package/src/pages/Index/Settings/AdminCenter/UserManagementPanel.tsx +49 -0
- package/src/pages/Index/Settings/SystemSettings.tsx +339 -0
- package/src/pages/Index/Settings/UserSettings.tsx +143 -0
- package/src/pages/Notifications.tsx +134 -0
- package/src/pages/build/BuildDetail.tsx +579 -0
- package/src/pages/build/BuildIndex.tsx +100 -0
- package/src/pages/company/CompanyDetail.tsx +352 -0
- package/src/pages/company/CustomerDetail.tsx +13 -0
- package/src/pages/company/ManufacturerDetail.tsx +13 -0
- package/src/pages/company/ManufacturerPartDetail.tsx +307 -0
- package/src/pages/company/SupplierDetail.tsx +13 -0
- package/src/pages/company/SupplierPartDetail.tsx +433 -0
- package/src/pages/core/CoreIndex.tsx +50 -0
- package/src/pages/core/GroupDetail.tsx +97 -0
- package/src/pages/core/UserDetail.tsx +193 -0
- package/src/pages/part/CategoryDetail.tsx +369 -0
- package/src/pages/part/PartAllocationPanel.tsx +40 -0
- package/src/pages/part/PartDetail.tsx +1071 -0
- package/src/pages/part/PartPricingPanel.tsx +155 -0
- package/src/pages/part/PartSchedulingDetail.tsx +315 -0
- package/src/pages/part/PartStocktakeDetail.tsx +285 -0
- package/src/pages/part/PartSupplierDetail.tsx +31 -0
- package/src/pages/part/pricing/BomPricingPanel.tsx +269 -0
- package/src/pages/part/pricing/PriceBreakPanel.tsx +182 -0
- package/src/pages/part/pricing/PricingOverviewPanel.tsx +338 -0
- package/src/pages/part/pricing/PricingPanel.tsx +82 -0
- package/src/pages/part/pricing/PurchaseHistoryPanel.tsx +134 -0
- package/src/pages/part/pricing/SaleHistoryPanel.tsx +95 -0
- package/src/pages/part/pricing/SupplierPricingPanel.tsx +80 -0
- package/src/pages/part/pricing/VariantPricingPanel.tsx +112 -0
- package/src/pages/purchasing/PurchaseOrderDetail.tsx +547 -0
- package/src/pages/purchasing/PurchasingIndex.tsx +131 -0
- package/src/pages/sales/ReturnOrderDetail.tsx +529 -0
- package/src/pages/sales/SalesIndex.tsx +148 -0
- package/src/pages/sales/SalesOrderDetail.tsx +593 -0
- package/src/pages/sales/SalesOrderShipmentDetail.tsx +385 -0
- package/src/pages/stock/LocationDetail.tsx +413 -0
- package/src/pages/stock/StockDetail.tsx +951 -0
- package/src/router.tsx +213 -0
- package/src/states/ApiState.tsx +85 -0
- package/src/states/IconState.tsx +94 -0
- package/src/states/LocalState.tsx +181 -0
- package/src/states/SettingsState.tsx +206 -0
- package/src/states/StatusState.tsx +55 -0
- package/src/states/UserState.tsx +202 -0
- package/src/states/states.tsx +69 -0
- package/src/tables/Column.tsx +29 -0
- package/src/tables/ColumnRenderers.tsx +320 -0
- package/src/tables/ColumnSelect.tsx +39 -0
- package/src/tables/Filter.tsx +297 -0
- package/src/tables/FilterSelectDrawer.tsx +358 -0
- package/src/tables/InvenTreeTable.tsx +750 -0
- package/src/tables/InvenTreeTableHeader.tsx +257 -0
- package/src/tables/RowActions.tsx +176 -0
- package/src/tables/RowExpansionIcon.tsx +16 -0
- package/src/tables/Search.tsx +42 -0
- package/src/tables/TableHoverCard.tsx +91 -0
- package/src/tables/bom/BomTable.tsx +590 -0
- package/src/tables/bom/UsedInTable.tsx +114 -0
- package/src/tables/build/BuildAllocatedStockTable.tsx +233 -0
- package/src/tables/build/BuildLineTable.tsx +800 -0
- package/src/tables/build/BuildOrderTable.tsx +226 -0
- package/src/tables/build/BuildOrderTestTable.tsx +265 -0
- package/src/tables/build/BuildOutputTable.tsx +599 -0
- package/src/tables/company/AddressTable.tsx +211 -0
- package/src/tables/company/CompanyTable.tsx +176 -0
- package/src/tables/company/ContactTable.tsx +182 -0
- package/src/tables/core/UserTable.tsx +88 -0
- package/src/tables/general/AttachmentTable.tsx +404 -0
- package/src/tables/general/BarcodeScanTable.tsx +124 -0
- package/src/tables/general/ExtraLineItemTable.tsx +174 -0
- package/src/tables/machine/MachineListTable.tsx +634 -0
- package/src/tables/machine/MachineTypeTable.tsx +395 -0
- package/src/tables/notifications/NotificationTable.tsx +60 -0
- package/src/tables/part/ParametricPartTable.tsx +297 -0
- package/src/tables/part/PartBuildAllocationsTable.tsx +128 -0
- package/src/tables/part/PartCategoryTable.tsx +208 -0
- package/src/tables/part/PartCategoryTemplateTable.tsx +157 -0
- package/src/tables/part/PartParameterTable.tsx +226 -0
- package/src/tables/part/PartParameterTemplateTable.tsx +168 -0
- package/src/tables/part/PartPurchaseOrdersTable.tsx +163 -0
- package/src/tables/part/PartSalesAllocationsTable.tsx +130 -0
- package/src/tables/part/PartTable.tsx +423 -0
- package/src/tables/part/PartTestTemplateTable.tsx +290 -0
- package/src/tables/part/PartThumbTable.tsx +230 -0
- package/src/tables/part/PartVariantTable.tsx +52 -0
- package/src/tables/part/RelatedPartTable.tsx +182 -0
- package/src/tables/part/SelectionListTable.tsx +134 -0
- package/src/tables/plugin/PluginErrorTable.tsx +58 -0
- package/src/tables/plugin/PluginListTable.tsx +440 -0
- package/src/tables/purchasing/ManufacturerPartParameterTable.tsx +136 -0
- package/src/tables/purchasing/ManufacturerPartTable.tsx +158 -0
- package/src/tables/purchasing/PurchaseOrderLineItemTable.tsx +424 -0
- package/src/tables/purchasing/PurchaseOrderTable.tsx +193 -0
- package/src/tables/purchasing/SupplierPartTable.tsx +281 -0
- package/src/tables/purchasing/SupplierPriceBreakTable.tsx +222 -0
- package/src/tables/sales/ReturnOrderLineItemTable.tsx +271 -0
- package/src/tables/sales/ReturnOrderTable.tsx +201 -0
- package/src/tables/sales/SalesOrderAllocationTable.tsx +330 -0
- package/src/tables/sales/SalesOrderLineItemTable.tsx +508 -0
- package/src/tables/sales/SalesOrderShipmentTable.tsx +225 -0
- package/src/tables/sales/SalesOrderTable.tsx +212 -0
- package/src/tables/settings/ApiTokenTable.tsx +203 -0
- package/src/tables/settings/BarcodeScanHistoryTable.tsx +281 -0
- package/src/tables/settings/CustomStateTable.tsx +226 -0
- package/src/tables/settings/CustomUnitsTable.tsx +125 -0
- package/src/tables/settings/ErrorTable.tsx +170 -0
- package/src/tables/settings/ExportSessionTable.tsx +60 -0
- package/src/tables/settings/FailedTasksTable.tsx +103 -0
- package/src/tables/settings/GroupTable.tsx +240 -0
- package/src/tables/settings/ImportSessionTable.tsx +175 -0
- package/src/tables/settings/PendingTasksTable.tsx +63 -0
- package/src/tables/settings/ProjectCodeTable.tsx +115 -0
- package/src/tables/settings/ScheduledTasksTable.tsx +62 -0
- package/src/tables/settings/StocktakeReportTable.tsx +111 -0
- package/src/tables/settings/TemplateTable.tsx +404 -0
- package/src/tables/settings/UserTable.tsx +329 -0
- package/src/tables/stock/InstalledItemsTable.tsx +146 -0
- package/src/tables/stock/LocationTypesTable.tsx +132 -0
- package/src/tables/stock/StockItemTable.tsx +707 -0
- package/src/tables/stock/StockItemTestResultTable.tsx +487 -0
- package/src/tables/stock/StockLocationTable.tsx +208 -0
- package/src/tables/stock/StockTrackingTable.tsx +244 -0
- package/src/theme.ts +5 -0
- package/src/views/DesktopAppView.tsx +28 -0
- package/src/views/MainView.tsx +38 -0
- package/src/views/MobileAppView.tsx +43 -0
- package/tests/baseFixtures.ts +93 -0
- package/tests/defaults.ts +18 -0
- package/tests/helpers.ts +122 -0
- package/tests/login.ts +97 -0
- package/tests/pages/pui_build.spec.ts +373 -0
- package/tests/pages/pui_company.spec.ts +40 -0
- package/tests/pages/pui_core.spec.ts +26 -0
- package/tests/pages/pui_dashboard.spec.ts +64 -0
- package/tests/pages/pui_part.spec.ts +413 -0
- package/tests/pages/pui_purchase_order.spec.ts +388 -0
- package/tests/pages/pui_sales_order.spec.ts +224 -0
- package/tests/pages/pui_scan.spec.ts +114 -0
- package/tests/pages/pui_stock.spec.ts +259 -0
- package/tests/pui_exporting.spec.ts +124 -0
- package/tests/pui_forms.spec.ts +131 -0
- package/tests/pui_general.spec.ts +60 -0
- package/tests/pui_login.spec.ts +74 -0
- package/tests/pui_modals.spec.ts +144 -0
- package/tests/pui_plugins.spec.ts +216 -0
- package/tests/pui_printing.spec.ts +149 -0
- package/tests/pui_settings.spec.ts +285 -0
- package/tests/pui_tables.spec.ts +65 -0
- package/tests/settings/selectionList.spec.ts +103 -0
- package/tests/settings.ts +54 -0
- package/tsconfig.json +25 -0
- package/tsconfig.lib.json +13 -0
- package/tsconfig.node.json +11 -0
- package/vite-env.d.ts +11 -0
- package/vite.config.ts +98 -0
- package/vite.lib.config.ts +50 -0
|
@@ -0,0 +1,1296 @@
|
|
|
1
|
+
import { t } from '@lingui/core/macro';
|
|
2
|
+
import { Flex, Group, Skeleton, Stack, Table, Text } from '@mantine/core';
|
|
3
|
+
import { useDisclosure } from '@mantine/hooks';
|
|
4
|
+
import { modals } from '@mantine/modals';
|
|
5
|
+
import {
|
|
6
|
+
IconCalendarExclamation,
|
|
7
|
+
IconCoins,
|
|
8
|
+
IconCurrencyDollar,
|
|
9
|
+
IconLink,
|
|
10
|
+
IconPackage,
|
|
11
|
+
IconUsersGroup
|
|
12
|
+
} from '@tabler/icons-react';
|
|
13
|
+
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
|
14
|
+
import { Suspense, useEffect, useMemo, useState } from 'react';
|
|
15
|
+
|
|
16
|
+
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
|
17
|
+
import { ModelType } from '@lib/enums/ModelType';
|
|
18
|
+
import dayjs from 'dayjs';
|
|
19
|
+
import { api } from '../App';
|
|
20
|
+
import { ActionButton } from '../components/buttons/ActionButton';
|
|
21
|
+
import RemoveRowButton from '../components/buttons/RemoveRowButton';
|
|
22
|
+
import { StandaloneField } from '../components/forms/StandaloneField';
|
|
23
|
+
|
|
24
|
+
import { apiUrl } from '@lib/functions/Api';
|
|
25
|
+
import type {
|
|
26
|
+
ApiFormAdjustFilterType,
|
|
27
|
+
ApiFormFieldChoice,
|
|
28
|
+
ApiFormFieldSet,
|
|
29
|
+
ApiFormModalProps
|
|
30
|
+
} from '@lib/types/Forms';
|
|
31
|
+
import {
|
|
32
|
+
TableFieldExtraRow,
|
|
33
|
+
type TableFieldRowProps
|
|
34
|
+
} from '../components/forms/fields/TableField';
|
|
35
|
+
import { Thumbnail } from '../components/images/Thumbnail';
|
|
36
|
+
import { StylishText } from '../components/items/StylishText';
|
|
37
|
+
import { StatusRenderer } from '../components/render/StatusRenderer';
|
|
38
|
+
import { InvenTreeIcon } from '../functions/icons';
|
|
39
|
+
import { useCreateApiFormModal, useDeleteApiFormModal } from '../hooks/UseForm';
|
|
40
|
+
import {
|
|
41
|
+
useBatchCodeGenerator,
|
|
42
|
+
useSerialNumberGenerator
|
|
43
|
+
} from '../hooks/UseGenerator';
|
|
44
|
+
import { useSerialNumberPlaceholder } from '../hooks/UsePlaceholder';
|
|
45
|
+
import { useGlobalSettingsState } from '../states/SettingsState';
|
|
46
|
+
import { StatusFilterOptions } from '../tables/Filter';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Construct a set of fields for creating / editing a StockItem instance
|
|
50
|
+
*/
|
|
51
|
+
export function useStockFields({
|
|
52
|
+
partId,
|
|
53
|
+
stockItem,
|
|
54
|
+
create = false
|
|
55
|
+
}: {
|
|
56
|
+
partId?: number;
|
|
57
|
+
stockItem?: any;
|
|
58
|
+
create: boolean;
|
|
59
|
+
}): ApiFormFieldSet {
|
|
60
|
+
const globalSettings = useGlobalSettingsState();
|
|
61
|
+
|
|
62
|
+
// Keep track of the "part" instance
|
|
63
|
+
const [partInstance, setPartInstance] = useState<any>({});
|
|
64
|
+
|
|
65
|
+
const [supplierPart, setSupplierPart] = useState<number | null>(null);
|
|
66
|
+
|
|
67
|
+
const [nextBatchCode, setNextBatchCode] = useState<string>('');
|
|
68
|
+
const [nextSerialNumber, setNextSerialNumber] = useState<string>('');
|
|
69
|
+
|
|
70
|
+
const [expiryDate, setExpiryDate] = useState<string | null>(null);
|
|
71
|
+
|
|
72
|
+
const batchGenerator = useBatchCodeGenerator((value: any) => {
|
|
73
|
+
if (value) {
|
|
74
|
+
setNextBatchCode(`${t`Next batch code`}: ${value}`);
|
|
75
|
+
} else {
|
|
76
|
+
setNextBatchCode('');
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const serialGenerator = useSerialNumberGenerator((value: any) => {
|
|
81
|
+
if (value) {
|
|
82
|
+
setNextSerialNumber(`${t`Next serial number`}: ${value}`);
|
|
83
|
+
} else {
|
|
84
|
+
setNextSerialNumber('');
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (partInstance?.pk) {
|
|
90
|
+
// Update the generators whenever the part ID changes
|
|
91
|
+
batchGenerator.update({ part: partInstance.pk });
|
|
92
|
+
serialGenerator.update({ part: partInstance.pk });
|
|
93
|
+
}
|
|
94
|
+
}, [partInstance.pk]);
|
|
95
|
+
|
|
96
|
+
return useMemo(() => {
|
|
97
|
+
const fields: ApiFormFieldSet = {
|
|
98
|
+
part: {
|
|
99
|
+
value: partInstance.pk,
|
|
100
|
+
disabled: !create,
|
|
101
|
+
filters: {
|
|
102
|
+
active: create ? true : undefined
|
|
103
|
+
},
|
|
104
|
+
onValueChange: (value, record) => {
|
|
105
|
+
// Update the tracked part instance
|
|
106
|
+
setPartInstance(record);
|
|
107
|
+
|
|
108
|
+
// Clear the 'supplier_part' field if the part is changed
|
|
109
|
+
setSupplierPart(null);
|
|
110
|
+
|
|
111
|
+
// Adjust the 'expiry date' for the stock item
|
|
112
|
+
const expiry_days = record?.default_expiry ?? 0;
|
|
113
|
+
|
|
114
|
+
if (expiry_days && expiry_days > 0) {
|
|
115
|
+
// Adjust the expiry date based on the part default expiry
|
|
116
|
+
setExpiryDate(
|
|
117
|
+
dayjs().add(expiry_days, 'days').format('YYYY-MM-DD')
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
supplier_part: {
|
|
123
|
+
hidden: partInstance?.purchaseable == false,
|
|
124
|
+
value: supplierPart,
|
|
125
|
+
onValueChange: (value) => {
|
|
126
|
+
setSupplierPart(value);
|
|
127
|
+
},
|
|
128
|
+
filters: {
|
|
129
|
+
part_detail: true,
|
|
130
|
+
supplier_detail: true,
|
|
131
|
+
part: partId
|
|
132
|
+
},
|
|
133
|
+
adjustFilters: (adjust: ApiFormAdjustFilterType) => {
|
|
134
|
+
if (adjust.data.part) {
|
|
135
|
+
adjust.filters['part'] = adjust.data.part;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return adjust.filters;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
use_pack_size: {
|
|
142
|
+
hidden: !create,
|
|
143
|
+
description: t`Add given quantity as packs instead of individual items`
|
|
144
|
+
},
|
|
145
|
+
location: {
|
|
146
|
+
// Cannot adjust location for existing stock items
|
|
147
|
+
hidden: !create,
|
|
148
|
+
onValueChange: (value) => {
|
|
149
|
+
batchGenerator.update({ location: value });
|
|
150
|
+
},
|
|
151
|
+
filters: {
|
|
152
|
+
structural: false
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
quantity: {
|
|
156
|
+
hidden: !create,
|
|
157
|
+
description: t`Enter initial quantity for this stock item`,
|
|
158
|
+
onValueChange: (value) => {
|
|
159
|
+
batchGenerator.update({ quantity: value });
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
serial_numbers: {
|
|
163
|
+
field_type: 'string',
|
|
164
|
+
label: t`Serial Numbers`,
|
|
165
|
+
disabled: partInstance?.trackable == false,
|
|
166
|
+
description: t`Enter serial numbers for new stock (or leave blank)`,
|
|
167
|
+
required: false,
|
|
168
|
+
hidden: !create,
|
|
169
|
+
placeholder: nextSerialNumber
|
|
170
|
+
},
|
|
171
|
+
serial: {
|
|
172
|
+
hidden:
|
|
173
|
+
create ||
|
|
174
|
+
partInstance.trackable == false ||
|
|
175
|
+
(stockItem?.quantity != undefined && stockItem?.quantity != 1)
|
|
176
|
+
},
|
|
177
|
+
batch: {
|
|
178
|
+
placeholder: nextBatchCode
|
|
179
|
+
},
|
|
180
|
+
status_custom_key: {
|
|
181
|
+
label: t`Stock Status`
|
|
182
|
+
},
|
|
183
|
+
expiry_date: {
|
|
184
|
+
icon: <IconCalendarExclamation />,
|
|
185
|
+
hidden: !globalSettings.isSet('STOCK_ENABLE_EXPIRY'),
|
|
186
|
+
value: expiryDate,
|
|
187
|
+
onValueChange: (value) => {
|
|
188
|
+
setExpiryDate(value);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
purchase_price: {
|
|
192
|
+
icon: <IconCurrencyDollar />
|
|
193
|
+
},
|
|
194
|
+
purchase_price_currency: {
|
|
195
|
+
icon: <IconCoins />
|
|
196
|
+
},
|
|
197
|
+
packaging: {
|
|
198
|
+
icon: <IconPackage />
|
|
199
|
+
},
|
|
200
|
+
link: {
|
|
201
|
+
icon: <IconLink />
|
|
202
|
+
},
|
|
203
|
+
owner: {
|
|
204
|
+
icon: <IconUsersGroup />
|
|
205
|
+
},
|
|
206
|
+
delete_on_deplete: {}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// Remove the expiry date field if it is not enabled
|
|
210
|
+
if (!globalSettings.isSet('STOCK_ENABLE_EXPIRY')) {
|
|
211
|
+
delete fields.expiry_date;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return fields;
|
|
215
|
+
}, [
|
|
216
|
+
stockItem,
|
|
217
|
+
expiryDate,
|
|
218
|
+
partInstance,
|
|
219
|
+
partId,
|
|
220
|
+
globalSettings,
|
|
221
|
+
supplierPart,
|
|
222
|
+
nextSerialNumber,
|
|
223
|
+
nextBatchCode,
|
|
224
|
+
create
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Launch a form to create a new StockItem instance
|
|
230
|
+
*/
|
|
231
|
+
export function useCreateStockItem() {
|
|
232
|
+
const fields = useStockFields({ create: true });
|
|
233
|
+
|
|
234
|
+
return useCreateApiFormModal({
|
|
235
|
+
url: ApiEndpoints.stock_item_list,
|
|
236
|
+
fields: fields,
|
|
237
|
+
title: t`Add Stock Item`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Form set for manually removing (uninstalling) a StockItem from an existing StockItem
|
|
243
|
+
*/
|
|
244
|
+
export function useStockItemUninstallFields(): ApiFormFieldSet {
|
|
245
|
+
return useMemo(() => {
|
|
246
|
+
return {
|
|
247
|
+
location: {
|
|
248
|
+
filters: {
|
|
249
|
+
structural: false
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
note: {}
|
|
253
|
+
};
|
|
254
|
+
}, []);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Form set for manually installing a StockItem into an existing StockItem
|
|
259
|
+
*/
|
|
260
|
+
export function useStockItemInstallFields({
|
|
261
|
+
stockItem
|
|
262
|
+
}: {
|
|
263
|
+
stockItem: any;
|
|
264
|
+
}): ApiFormFieldSet {
|
|
265
|
+
const globalSettings = useGlobalSettingsState();
|
|
266
|
+
|
|
267
|
+
const [selectedPart, setSelectedPart] = useState<number | null>(null);
|
|
268
|
+
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
setSelectedPart(null);
|
|
271
|
+
}, [stockItem]);
|
|
272
|
+
|
|
273
|
+
return useMemo(() => {
|
|
274
|
+
// Note: The 'part' field is not a part of the API endpoint, so we construct it manually
|
|
275
|
+
return {
|
|
276
|
+
part: {
|
|
277
|
+
field_type: 'related field',
|
|
278
|
+
required: true,
|
|
279
|
+
exclude: true,
|
|
280
|
+
label: t`Part`,
|
|
281
|
+
description: t`Select the part to install`,
|
|
282
|
+
model: ModelType.part,
|
|
283
|
+
api_url: apiUrl(ApiEndpoints.part_list),
|
|
284
|
+
onValueChange: (value) => {
|
|
285
|
+
setSelectedPart(value);
|
|
286
|
+
},
|
|
287
|
+
filters: {
|
|
288
|
+
trackable: true,
|
|
289
|
+
in_bom_for: globalSettings.isSet('STOCK_ENFORCE_BOM_INSTALLATION')
|
|
290
|
+
? stockItem.part
|
|
291
|
+
: undefined
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
stock_item: {
|
|
295
|
+
disabled: !selectedPart,
|
|
296
|
+
filters: {
|
|
297
|
+
part_detail: true,
|
|
298
|
+
in_stock: true,
|
|
299
|
+
available: true,
|
|
300
|
+
tracked: true,
|
|
301
|
+
part: selectedPart ? selectedPart : undefined
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
quantity: {},
|
|
305
|
+
note: {}
|
|
306
|
+
};
|
|
307
|
+
}, [globalSettings, selectedPart, stockItem]);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Form set for serializing an existing StockItem
|
|
312
|
+
*/
|
|
313
|
+
export function useStockItemSerializeFields({
|
|
314
|
+
partId,
|
|
315
|
+
trackable
|
|
316
|
+
}: {
|
|
317
|
+
partId: number;
|
|
318
|
+
trackable: boolean;
|
|
319
|
+
}) {
|
|
320
|
+
const snPlaceholder = useSerialNumberPlaceholder({
|
|
321
|
+
partId: partId,
|
|
322
|
+
key: 'stock-item-serialize',
|
|
323
|
+
enabled: trackable
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
return useMemo(() => {
|
|
327
|
+
return {
|
|
328
|
+
quantity: {},
|
|
329
|
+
serial_numbers: {
|
|
330
|
+
placeholder: snPlaceholder
|
|
331
|
+
},
|
|
332
|
+
destination: {}
|
|
333
|
+
};
|
|
334
|
+
}, [snPlaceholder]);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function StockItemDefaultMove({
|
|
338
|
+
stockItem,
|
|
339
|
+
value
|
|
340
|
+
}: Readonly<{
|
|
341
|
+
stockItem: any;
|
|
342
|
+
value: any;
|
|
343
|
+
}>) {
|
|
344
|
+
const { data } = useSuspenseQuery({
|
|
345
|
+
queryKey: [
|
|
346
|
+
'location',
|
|
347
|
+
stockItem.part_detail?.default_location ??
|
|
348
|
+
stockItem.part_detail?.category_default_location
|
|
349
|
+
],
|
|
350
|
+
queryFn: async () => {
|
|
351
|
+
const url = apiUrl(
|
|
352
|
+
ApiEndpoints.stock_location_list,
|
|
353
|
+
stockItem.part_detail?.default_location ??
|
|
354
|
+
stockItem.part_detail?.category_default_location
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
return api
|
|
358
|
+
.get(url)
|
|
359
|
+
.then((response) => {
|
|
360
|
+
switch (response.status) {
|
|
361
|
+
case 200:
|
|
362
|
+
return response.data;
|
|
363
|
+
default:
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
.catch(() => {
|
|
368
|
+
return null;
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
return (
|
|
374
|
+
<Flex gap='sm' justify='space-evenly' align='center'>
|
|
375
|
+
<Flex gap='sm' direction='column' align='center'>
|
|
376
|
+
<Text>
|
|
377
|
+
{value} x {stockItem.part_detail.name}
|
|
378
|
+
</Text>
|
|
379
|
+
<Thumbnail
|
|
380
|
+
src={stockItem.part_detail.thumbnail}
|
|
381
|
+
size={80}
|
|
382
|
+
align='center'
|
|
383
|
+
/>
|
|
384
|
+
</Flex>
|
|
385
|
+
<Flex direction='column' gap='sm' align='center'>
|
|
386
|
+
<Text>{stockItem.location_detail?.pathstring ?? '-'}</Text>
|
|
387
|
+
<InvenTreeIcon icon='arrow_down' />
|
|
388
|
+
<Suspense fallback={<Skeleton width='150px' />}>
|
|
389
|
+
<Text>{data?.pathstring}</Text>
|
|
390
|
+
</Suspense>
|
|
391
|
+
</Flex>
|
|
392
|
+
</Flex>
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function moveToDefault(
|
|
397
|
+
stockItem: any,
|
|
398
|
+
value: StockItemQuantity,
|
|
399
|
+
refresh: () => void
|
|
400
|
+
) {
|
|
401
|
+
modals.openConfirmModal({
|
|
402
|
+
title: <StylishText>{t`Confirm Stock Transfer`}</StylishText>,
|
|
403
|
+
children: <StockItemDefaultMove stockItem={stockItem} value={value} />,
|
|
404
|
+
onConfirm: () => {
|
|
405
|
+
if (
|
|
406
|
+
stockItem.location === stockItem.part_detail?.default_location ||
|
|
407
|
+
stockItem.location === stockItem.part_detail?.category_default_location
|
|
408
|
+
) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
api
|
|
412
|
+
.post(apiUrl(ApiEndpoints.stock_transfer), {
|
|
413
|
+
items: [
|
|
414
|
+
{
|
|
415
|
+
pk: stockItem.pk,
|
|
416
|
+
quantity: value,
|
|
417
|
+
batch: stockItem.batch,
|
|
418
|
+
status: stockItem.status
|
|
419
|
+
}
|
|
420
|
+
],
|
|
421
|
+
location:
|
|
422
|
+
stockItem.part_detail?.default_location ??
|
|
423
|
+
stockItem.part_detail?.category_default_location
|
|
424
|
+
})
|
|
425
|
+
.then((response) => {
|
|
426
|
+
refresh();
|
|
427
|
+
return response.data;
|
|
428
|
+
})
|
|
429
|
+
.catch(() => {
|
|
430
|
+
return null;
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
type StockAdjustmentItemWithRecord = {
|
|
437
|
+
obj: any;
|
|
438
|
+
} & StockAdjustmentItem;
|
|
439
|
+
|
|
440
|
+
type TableFieldRefreshFn = (idx: number) => void;
|
|
441
|
+
type TableFieldChangeFn = (idx: number, key: string, value: any) => void;
|
|
442
|
+
|
|
443
|
+
type StockRow = {
|
|
444
|
+
item: StockAdjustmentItemWithRecord;
|
|
445
|
+
idx: number;
|
|
446
|
+
changeFn: TableFieldChangeFn;
|
|
447
|
+
removeFn: TableFieldRefreshFn;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
function StockOperationsRow({
|
|
451
|
+
props,
|
|
452
|
+
transfer = false,
|
|
453
|
+
changeStatus = false,
|
|
454
|
+
add = false,
|
|
455
|
+
setMax = false,
|
|
456
|
+
merge = false,
|
|
457
|
+
record
|
|
458
|
+
}: {
|
|
459
|
+
props: TableFieldRowProps;
|
|
460
|
+
transfer?: boolean;
|
|
461
|
+
changeStatus?: boolean;
|
|
462
|
+
add?: boolean;
|
|
463
|
+
setMax?: boolean;
|
|
464
|
+
merge?: boolean;
|
|
465
|
+
record?: any;
|
|
466
|
+
}) {
|
|
467
|
+
const statusOptions: ApiFormFieldChoice[] = useMemo(() => {
|
|
468
|
+
return (
|
|
469
|
+
StatusFilterOptions(ModelType.stockitem)()?.map((choice) => {
|
|
470
|
+
return {
|
|
471
|
+
value: choice.value,
|
|
472
|
+
display_name: choice.label
|
|
473
|
+
};
|
|
474
|
+
}) ?? []
|
|
475
|
+
);
|
|
476
|
+
}, []);
|
|
477
|
+
|
|
478
|
+
const [quantity, setQuantity] = useState<StockItemQuantity>(
|
|
479
|
+
add ? 0 : (props.item?.quantity ?? 0)
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
const [status, setStatus] = useState<number | undefined>(undefined);
|
|
483
|
+
|
|
484
|
+
const removeAndRefresh = () => {
|
|
485
|
+
props.removeFn(props.idx);
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const [packagingOpen, packagingHandlers] = useDisclosure(false, {
|
|
489
|
+
onOpen: () => {
|
|
490
|
+
if (transfer) {
|
|
491
|
+
props.changeFn(props.idx, 'packaging', record?.packaging || undefined);
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
onClose: () => {
|
|
495
|
+
if (transfer) {
|
|
496
|
+
props.changeFn(props.idx, 'packaging', undefined);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const [statusOpen, statusHandlers] = useDisclosure(false, {
|
|
502
|
+
onOpen: () => {
|
|
503
|
+
setStatus(record?.status_custom_key || record?.status || undefined);
|
|
504
|
+
props.changeFn(props.idx, 'status', record?.status || undefined);
|
|
505
|
+
},
|
|
506
|
+
onClose: () => {
|
|
507
|
+
setStatus(undefined);
|
|
508
|
+
props.changeFn(props.idx, 'status', undefined);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
const stockString: string = useMemo(() => {
|
|
513
|
+
if (!record) {
|
|
514
|
+
return '-';
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (!record.serial) {
|
|
518
|
+
return `${record.quantity}`;
|
|
519
|
+
} else {
|
|
520
|
+
return `#${record.serial}`;
|
|
521
|
+
}
|
|
522
|
+
}, [record]);
|
|
523
|
+
|
|
524
|
+
return !record ? (
|
|
525
|
+
<div>{t`Loading...`}</div>
|
|
526
|
+
) : (
|
|
527
|
+
<>
|
|
528
|
+
<Table.Tr>
|
|
529
|
+
<Table.Td>
|
|
530
|
+
<Stack gap='xs'>
|
|
531
|
+
<Flex gap='sm' align='center'>
|
|
532
|
+
<Thumbnail
|
|
533
|
+
size={40}
|
|
534
|
+
src={record.part_detail?.thumbnail}
|
|
535
|
+
align='center'
|
|
536
|
+
/>
|
|
537
|
+
<div>{record.part_detail?.name}</div>
|
|
538
|
+
</Flex>
|
|
539
|
+
{props.rowErrors?.pk?.message && (
|
|
540
|
+
<Text c='red' size='xs'>
|
|
541
|
+
{props.rowErrors.pk.message}
|
|
542
|
+
</Text>
|
|
543
|
+
)}
|
|
544
|
+
</Stack>
|
|
545
|
+
</Table.Td>
|
|
546
|
+
<Table.Td>
|
|
547
|
+
{record.location ? record.location_detail?.pathstring : '-'}
|
|
548
|
+
</Table.Td>
|
|
549
|
+
<Table.Td>{record.batch ? record.batch : '-'}</Table.Td>
|
|
550
|
+
<Table.Td>
|
|
551
|
+
<Group grow justify='space-between' wrap='nowrap'>
|
|
552
|
+
<Text>{stockString}</Text>
|
|
553
|
+
<StatusRenderer
|
|
554
|
+
status={record.status_custom_key}
|
|
555
|
+
type={ModelType.stockitem}
|
|
556
|
+
/>
|
|
557
|
+
</Group>
|
|
558
|
+
</Table.Td>
|
|
559
|
+
{!merge && (
|
|
560
|
+
<Table.Td>
|
|
561
|
+
<StandaloneField
|
|
562
|
+
fieldName='quantity'
|
|
563
|
+
fieldDefinition={{
|
|
564
|
+
field_type: 'number',
|
|
565
|
+
value: quantity,
|
|
566
|
+
onValueChange: (value: any) => {
|
|
567
|
+
setQuantity(value);
|
|
568
|
+
props.changeFn(props.idx, 'quantity', value);
|
|
569
|
+
}
|
|
570
|
+
}}
|
|
571
|
+
error={props.rowErrors?.quantity?.message}
|
|
572
|
+
/>
|
|
573
|
+
</Table.Td>
|
|
574
|
+
)}
|
|
575
|
+
<Table.Td>
|
|
576
|
+
<Flex gap='3px'>
|
|
577
|
+
{transfer && (
|
|
578
|
+
<ActionButton
|
|
579
|
+
onClick={() =>
|
|
580
|
+
moveToDefault(record, props.item.quantity, removeAndRefresh)
|
|
581
|
+
}
|
|
582
|
+
icon={<InvenTreeIcon icon='default_location' />}
|
|
583
|
+
tooltip={t`Move to default location`}
|
|
584
|
+
tooltipAlignment='top'
|
|
585
|
+
disabled={
|
|
586
|
+
!record.part_detail?.default_location &&
|
|
587
|
+
!record.part_detail?.category_default_location
|
|
588
|
+
}
|
|
589
|
+
/>
|
|
590
|
+
)}
|
|
591
|
+
{changeStatus && (
|
|
592
|
+
<ActionButton
|
|
593
|
+
size='sm'
|
|
594
|
+
icon={<InvenTreeIcon icon='status' />}
|
|
595
|
+
tooltip={t`Change Status`}
|
|
596
|
+
onClick={() => statusHandlers.toggle()}
|
|
597
|
+
variant={statusOpen ? 'filled' : 'transparent'}
|
|
598
|
+
/>
|
|
599
|
+
)}
|
|
600
|
+
{transfer && (
|
|
601
|
+
<ActionButton
|
|
602
|
+
size='sm'
|
|
603
|
+
icon={<InvenTreeIcon icon='packaging' />}
|
|
604
|
+
tooltip={t`Adjust Packaging`}
|
|
605
|
+
onClick={() => packagingHandlers.toggle()}
|
|
606
|
+
variant={packagingOpen ? 'filled' : 'transparent'}
|
|
607
|
+
/>
|
|
608
|
+
)}
|
|
609
|
+
<RemoveRowButton onClick={() => props.removeFn(props.idx)} />
|
|
610
|
+
</Flex>
|
|
611
|
+
</Table.Td>
|
|
612
|
+
</Table.Tr>
|
|
613
|
+
{changeStatus && (
|
|
614
|
+
<TableFieldExtraRow
|
|
615
|
+
visible={statusOpen}
|
|
616
|
+
onValueChange={(value: any) => {
|
|
617
|
+
setStatus(value);
|
|
618
|
+
props.changeFn(props.idx, 'status', value || undefined);
|
|
619
|
+
}}
|
|
620
|
+
fieldName='status'
|
|
621
|
+
fieldDefinition={{
|
|
622
|
+
field_type: 'choice',
|
|
623
|
+
label: t`Status`,
|
|
624
|
+
choices: statusOptions,
|
|
625
|
+
value: status
|
|
626
|
+
}}
|
|
627
|
+
defaultValue={status}
|
|
628
|
+
/>
|
|
629
|
+
)}
|
|
630
|
+
{transfer && (
|
|
631
|
+
<TableFieldExtraRow
|
|
632
|
+
visible={transfer && packagingOpen}
|
|
633
|
+
onValueChange={(value: any) => {
|
|
634
|
+
props.changeFn(props.idx, 'packaging', value || undefined);
|
|
635
|
+
}}
|
|
636
|
+
fieldName='packaging'
|
|
637
|
+
fieldDefinition={{
|
|
638
|
+
field_type: 'string',
|
|
639
|
+
label: t`Packaging`
|
|
640
|
+
}}
|
|
641
|
+
defaultValue={record.packaging}
|
|
642
|
+
/>
|
|
643
|
+
)}
|
|
644
|
+
</>
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
type StockItemQuantity = number | '' | undefined;
|
|
649
|
+
|
|
650
|
+
type StockAdjustmentItem = {
|
|
651
|
+
pk: number;
|
|
652
|
+
quantity: StockItemQuantity;
|
|
653
|
+
batch?: string;
|
|
654
|
+
status?: number | '' | null;
|
|
655
|
+
packaging?: string;
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
function mapAdjustmentItems(items: any[]) {
|
|
659
|
+
const mappedItems: StockAdjustmentItemWithRecord[] = items.map((elem) => {
|
|
660
|
+
return {
|
|
661
|
+
pk: elem.pk,
|
|
662
|
+
quantity: elem.quantity,
|
|
663
|
+
batch: elem.batch || undefined,
|
|
664
|
+
status: elem.status || undefined,
|
|
665
|
+
packaging: elem.packaging || undefined,
|
|
666
|
+
obj: elem
|
|
667
|
+
};
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
return mappedItems;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function stockTransferFields(items: any[]): ApiFormFieldSet {
|
|
674
|
+
if (!items) {
|
|
675
|
+
return {};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
679
|
+
|
|
680
|
+
const fields: ApiFormFieldSet = {
|
|
681
|
+
items: {
|
|
682
|
+
field_type: 'table',
|
|
683
|
+
value: mapAdjustmentItems(items),
|
|
684
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
685
|
+
const record = records[row.item.pk];
|
|
686
|
+
|
|
687
|
+
return (
|
|
688
|
+
<StockOperationsRow
|
|
689
|
+
props={row}
|
|
690
|
+
transfer
|
|
691
|
+
changeStatus
|
|
692
|
+
setMax
|
|
693
|
+
key={record.pk}
|
|
694
|
+
record={record}
|
|
695
|
+
/>
|
|
696
|
+
);
|
|
697
|
+
},
|
|
698
|
+
headers: [
|
|
699
|
+
{ title: t`Part` },
|
|
700
|
+
{ title: t`Location` },
|
|
701
|
+
{ title: t`Batch` },
|
|
702
|
+
{ title: t`Stock` },
|
|
703
|
+
{ title: t`Move`, style: { width: '200px' } },
|
|
704
|
+
{ title: t`Actions` }
|
|
705
|
+
]
|
|
706
|
+
},
|
|
707
|
+
location: {
|
|
708
|
+
filters: {
|
|
709
|
+
structural: false
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
notes: {}
|
|
713
|
+
};
|
|
714
|
+
return fields;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function stockRemoveFields(items: any[]): ApiFormFieldSet {
|
|
718
|
+
if (!items) {
|
|
719
|
+
return {};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
723
|
+
|
|
724
|
+
const fields: ApiFormFieldSet = {
|
|
725
|
+
items: {
|
|
726
|
+
field_type: 'table',
|
|
727
|
+
value: mapAdjustmentItems(items),
|
|
728
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
729
|
+
const record = records[row.item.pk];
|
|
730
|
+
|
|
731
|
+
return (
|
|
732
|
+
<StockOperationsRow
|
|
733
|
+
props={row}
|
|
734
|
+
setMax
|
|
735
|
+
changeStatus
|
|
736
|
+
add
|
|
737
|
+
key={record.pk}
|
|
738
|
+
record={record}
|
|
739
|
+
/>
|
|
740
|
+
);
|
|
741
|
+
},
|
|
742
|
+
headers: [
|
|
743
|
+
{ title: t`Part` },
|
|
744
|
+
{ title: t`Location` },
|
|
745
|
+
{ title: t`Batch` },
|
|
746
|
+
{ title: t`In Stock` },
|
|
747
|
+
{ title: t`Remove`, style: { width: '200px' } },
|
|
748
|
+
{ title: t`Actions` }
|
|
749
|
+
]
|
|
750
|
+
},
|
|
751
|
+
notes: {}
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
return fields;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function stockAddFields(items: any[]): ApiFormFieldSet {
|
|
758
|
+
if (!items) {
|
|
759
|
+
return {};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
763
|
+
|
|
764
|
+
const fields: ApiFormFieldSet = {
|
|
765
|
+
items: {
|
|
766
|
+
field_type: 'table',
|
|
767
|
+
value: mapAdjustmentItems(items),
|
|
768
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
769
|
+
const record = records[row.item.pk];
|
|
770
|
+
|
|
771
|
+
return (
|
|
772
|
+
<StockOperationsRow
|
|
773
|
+
changeStatus
|
|
774
|
+
props={row}
|
|
775
|
+
add
|
|
776
|
+
key={record.pk}
|
|
777
|
+
record={record}
|
|
778
|
+
/>
|
|
779
|
+
);
|
|
780
|
+
},
|
|
781
|
+
headers: [
|
|
782
|
+
{ title: t`Part` },
|
|
783
|
+
{ title: t`Location` },
|
|
784
|
+
{ title: t`Batch` },
|
|
785
|
+
{ title: t`In Stock` },
|
|
786
|
+
{ title: t`Add`, style: { width: '200px' } },
|
|
787
|
+
{ title: t`Actions` }
|
|
788
|
+
]
|
|
789
|
+
},
|
|
790
|
+
notes: {}
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
return fields;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function stockCountFields(items: any[]): ApiFormFieldSet {
|
|
797
|
+
if (!items) {
|
|
798
|
+
return {};
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
802
|
+
|
|
803
|
+
const fields: ApiFormFieldSet = {
|
|
804
|
+
items: {
|
|
805
|
+
field_type: 'table',
|
|
806
|
+
value: mapAdjustmentItems(items),
|
|
807
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
808
|
+
return (
|
|
809
|
+
<StockOperationsRow
|
|
810
|
+
props={row}
|
|
811
|
+
changeStatus
|
|
812
|
+
key={row.item.pk}
|
|
813
|
+
record={records[row.item.pk]}
|
|
814
|
+
/>
|
|
815
|
+
);
|
|
816
|
+
},
|
|
817
|
+
headers: [
|
|
818
|
+
{ title: t`Part` },
|
|
819
|
+
{ title: t`Location` },
|
|
820
|
+
{ title: t`Batch` },
|
|
821
|
+
{ title: t`In Stock` },
|
|
822
|
+
{ title: t`Count`, style: { width: '200px' } },
|
|
823
|
+
{ title: t`Actions` }
|
|
824
|
+
]
|
|
825
|
+
},
|
|
826
|
+
notes: {}
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
return fields;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function stockChangeStatusFields(items: any[]): ApiFormFieldSet {
|
|
833
|
+
if (!items) {
|
|
834
|
+
return {};
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
838
|
+
|
|
839
|
+
const fields: ApiFormFieldSet = {
|
|
840
|
+
items: {
|
|
841
|
+
field_type: 'table',
|
|
842
|
+
value: items.map((elem) => {
|
|
843
|
+
return elem.pk;
|
|
844
|
+
}),
|
|
845
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
846
|
+
return (
|
|
847
|
+
<StockOperationsRow
|
|
848
|
+
props={row}
|
|
849
|
+
key={row.item}
|
|
850
|
+
merge
|
|
851
|
+
record={records[row.item]}
|
|
852
|
+
/>
|
|
853
|
+
);
|
|
854
|
+
},
|
|
855
|
+
headers: [
|
|
856
|
+
{ title: t`Part` },
|
|
857
|
+
{ title: t`Location` },
|
|
858
|
+
{ title: t`Batch` },
|
|
859
|
+
{ title: t`In Stock` },
|
|
860
|
+
{ title: '', style: { width: '50px' } }
|
|
861
|
+
]
|
|
862
|
+
},
|
|
863
|
+
status: {},
|
|
864
|
+
note: {}
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
return fields;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function stockMergeFields(items: any[]): ApiFormFieldSet {
|
|
871
|
+
if (!items) {
|
|
872
|
+
return {};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
876
|
+
|
|
877
|
+
const fields: ApiFormFieldSet = {
|
|
878
|
+
items: {
|
|
879
|
+
field_type: 'table',
|
|
880
|
+
value: items.map((elem) => {
|
|
881
|
+
return {
|
|
882
|
+
item: elem.pk,
|
|
883
|
+
obj: elem
|
|
884
|
+
};
|
|
885
|
+
}),
|
|
886
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
887
|
+
return (
|
|
888
|
+
<StockOperationsRow
|
|
889
|
+
props={row}
|
|
890
|
+
key={row.item.item}
|
|
891
|
+
merge
|
|
892
|
+
changeStatus
|
|
893
|
+
record={records[row.item.item]}
|
|
894
|
+
/>
|
|
895
|
+
);
|
|
896
|
+
},
|
|
897
|
+
headers: [
|
|
898
|
+
{ title: t`Part` },
|
|
899
|
+
{ title: t`Location` },
|
|
900
|
+
{ title: t`Batch` },
|
|
901
|
+
{ title: t`In Stock` },
|
|
902
|
+
{ title: t`Actions` }
|
|
903
|
+
]
|
|
904
|
+
},
|
|
905
|
+
location: {
|
|
906
|
+
default: items[0]?.part_detail.default_location,
|
|
907
|
+
filters: {
|
|
908
|
+
structural: false
|
|
909
|
+
}
|
|
910
|
+
},
|
|
911
|
+
notes: {},
|
|
912
|
+
allow_mismatched_suppliers: {},
|
|
913
|
+
allow_mismatched_status: {}
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
return fields;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function stockAssignFields(items: any[]): ApiFormFieldSet {
|
|
920
|
+
if (!items) {
|
|
921
|
+
return {};
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
925
|
+
|
|
926
|
+
const fields: ApiFormFieldSet = {
|
|
927
|
+
items: {
|
|
928
|
+
field_type: 'table',
|
|
929
|
+
value: items.map((elem) => {
|
|
930
|
+
return {
|
|
931
|
+
item: elem.pk,
|
|
932
|
+
obj: elem
|
|
933
|
+
};
|
|
934
|
+
}),
|
|
935
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
936
|
+
return (
|
|
937
|
+
<StockOperationsRow
|
|
938
|
+
props={row}
|
|
939
|
+
key={row.item.item}
|
|
940
|
+
merge
|
|
941
|
+
record={records[row.item.item]}
|
|
942
|
+
/>
|
|
943
|
+
);
|
|
944
|
+
},
|
|
945
|
+
headers: [
|
|
946
|
+
{ title: t`Part` },
|
|
947
|
+
{ title: t`Location` },
|
|
948
|
+
{ title: t`Batch` },
|
|
949
|
+
{ title: t`In Stock` },
|
|
950
|
+
{ title: '', style: { width: '50px' } }
|
|
951
|
+
]
|
|
952
|
+
},
|
|
953
|
+
customer: {
|
|
954
|
+
filters: {
|
|
955
|
+
is_customer: true
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
notes: {}
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
return fields;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function stockDeleteFields(items: any[]): ApiFormFieldSet {
|
|
965
|
+
if (!items) {
|
|
966
|
+
return {};
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
|
|
970
|
+
|
|
971
|
+
const fields: ApiFormFieldSet = {
|
|
972
|
+
items: {
|
|
973
|
+
field_type: 'table',
|
|
974
|
+
value: items.map((elem) => {
|
|
975
|
+
return elem.pk;
|
|
976
|
+
}),
|
|
977
|
+
modelRenderer: (row: TableFieldRowProps) => {
|
|
978
|
+
const record = records[row.item];
|
|
979
|
+
|
|
980
|
+
return (
|
|
981
|
+
<StockOperationsRow
|
|
982
|
+
props={row}
|
|
983
|
+
key={record.pk}
|
|
984
|
+
merge
|
|
985
|
+
record={record}
|
|
986
|
+
/>
|
|
987
|
+
);
|
|
988
|
+
},
|
|
989
|
+
headers: [
|
|
990
|
+
{ title: t`Part` },
|
|
991
|
+
{ title: t`Location` },
|
|
992
|
+
{ title: t`Batch` },
|
|
993
|
+
{ title: t`In Stock` },
|
|
994
|
+
{ title: '', style: { width: '50px' } }
|
|
995
|
+
]
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
return fields;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
type apiModalFunc = (props: ApiFormModalProps) => {
|
|
1003
|
+
open: () => void;
|
|
1004
|
+
close: () => void;
|
|
1005
|
+
toggle: () => void;
|
|
1006
|
+
modal: JSX.Element;
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
function stockOperationModal({
|
|
1010
|
+
items,
|
|
1011
|
+
pk,
|
|
1012
|
+
model,
|
|
1013
|
+
refresh,
|
|
1014
|
+
fieldGenerator,
|
|
1015
|
+
endpoint,
|
|
1016
|
+
filters,
|
|
1017
|
+
title,
|
|
1018
|
+
successMessage,
|
|
1019
|
+
modalFunc = useCreateApiFormModal
|
|
1020
|
+
}: {
|
|
1021
|
+
items?: object;
|
|
1022
|
+
pk?: number;
|
|
1023
|
+
filters?: any;
|
|
1024
|
+
model: ModelType | string;
|
|
1025
|
+
refresh: () => void;
|
|
1026
|
+
fieldGenerator: (items: any[]) => ApiFormFieldSet;
|
|
1027
|
+
endpoint: ApiEndpoints;
|
|
1028
|
+
title: string;
|
|
1029
|
+
successMessage?: string;
|
|
1030
|
+
modalFunc?: apiModalFunc;
|
|
1031
|
+
}) {
|
|
1032
|
+
const baseParams: any = {
|
|
1033
|
+
part_detail: true,
|
|
1034
|
+
location_detail: true,
|
|
1035
|
+
cascade: false
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
const params = useMemo(() => {
|
|
1039
|
+
const query_params: any = {
|
|
1040
|
+
...baseParams,
|
|
1041
|
+
...(filters ?? {})
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
query_params[model] =
|
|
1045
|
+
pk === undefined && model === 'location' ? 'null' : pk;
|
|
1046
|
+
|
|
1047
|
+
return query_params;
|
|
1048
|
+
}, [baseParams, filters, model, pk]);
|
|
1049
|
+
|
|
1050
|
+
const { data } = useQuery({
|
|
1051
|
+
queryKey: ['stockitems', model, pk, items, params],
|
|
1052
|
+
queryFn: async () => {
|
|
1053
|
+
if (items) {
|
|
1054
|
+
return Array.isArray(items) ? items : [items];
|
|
1055
|
+
}
|
|
1056
|
+
const url = apiUrl(ApiEndpoints.stock_item_list);
|
|
1057
|
+
|
|
1058
|
+
return api
|
|
1059
|
+
.get(url, {
|
|
1060
|
+
params: params
|
|
1061
|
+
})
|
|
1062
|
+
.then((response) => {
|
|
1063
|
+
if (response.status === 200) {
|
|
1064
|
+
return response.data;
|
|
1065
|
+
}
|
|
1066
|
+
})
|
|
1067
|
+
.catch(() => {
|
|
1068
|
+
return null;
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
|
|
1073
|
+
const fields = useMemo(() => {
|
|
1074
|
+
return fieldGenerator(data);
|
|
1075
|
+
}, [data]);
|
|
1076
|
+
|
|
1077
|
+
return modalFunc({
|
|
1078
|
+
url: endpoint,
|
|
1079
|
+
fields: fields,
|
|
1080
|
+
title: title,
|
|
1081
|
+
size: '80%',
|
|
1082
|
+
successMessage: successMessage,
|
|
1083
|
+
onFormSuccess: () => refresh()
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
export type StockOperationProps = {
|
|
1088
|
+
items?: any[];
|
|
1089
|
+
pk?: number;
|
|
1090
|
+
filters?: any;
|
|
1091
|
+
model: ModelType.stockitem | 'location' | ModelType.part;
|
|
1092
|
+
refresh: () => void;
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
export function useAddStockItem(props: StockOperationProps) {
|
|
1096
|
+
return stockOperationModal({
|
|
1097
|
+
...props,
|
|
1098
|
+
fieldGenerator: stockAddFields,
|
|
1099
|
+
endpoint: ApiEndpoints.stock_add,
|
|
1100
|
+
title: t`Add Stock`,
|
|
1101
|
+
successMessage: t`Stock added`
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
export function useRemoveStockItem(props: StockOperationProps) {
|
|
1106
|
+
return stockOperationModal({
|
|
1107
|
+
...props,
|
|
1108
|
+
fieldGenerator: stockRemoveFields,
|
|
1109
|
+
endpoint: ApiEndpoints.stock_remove,
|
|
1110
|
+
title: t`Remove Stock`,
|
|
1111
|
+
successMessage: t`Stock removed`
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
export function useTransferStockItem(props: StockOperationProps) {
|
|
1116
|
+
return stockOperationModal({
|
|
1117
|
+
...props,
|
|
1118
|
+
fieldGenerator: stockTransferFields,
|
|
1119
|
+
endpoint: ApiEndpoints.stock_transfer,
|
|
1120
|
+
title: t`Transfer Stock`,
|
|
1121
|
+
successMessage: t`Stock transferred`
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
export function useCountStockItem(props: StockOperationProps) {
|
|
1126
|
+
return stockOperationModal({
|
|
1127
|
+
...props,
|
|
1128
|
+
fieldGenerator: stockCountFields,
|
|
1129
|
+
endpoint: ApiEndpoints.stock_count,
|
|
1130
|
+
title: t`Count Stock`,
|
|
1131
|
+
successMessage: t`Stock counted`
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
export function useChangeStockStatus(props: StockOperationProps) {
|
|
1136
|
+
return stockOperationModal({
|
|
1137
|
+
...props,
|
|
1138
|
+
fieldGenerator: stockChangeStatusFields,
|
|
1139
|
+
endpoint: ApiEndpoints.stock_change_status,
|
|
1140
|
+
title: t`Change Stock Status`,
|
|
1141
|
+
successMessage: t`Stock status changed`
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
export function useMergeStockItem(props: StockOperationProps) {
|
|
1146
|
+
return stockOperationModal({
|
|
1147
|
+
...props,
|
|
1148
|
+
fieldGenerator: stockMergeFields,
|
|
1149
|
+
endpoint: ApiEndpoints.stock_merge,
|
|
1150
|
+
title: t`Merge Stock`,
|
|
1151
|
+
successMessage: t`Stock merged`
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
export function useAssignStockItem(props: StockOperationProps) {
|
|
1156
|
+
// Filter items - only allow 'salable' items
|
|
1157
|
+
const items = useMemo(() => {
|
|
1158
|
+
return props.items?.filter((item) => item?.part_detail?.salable);
|
|
1159
|
+
}, [props.items]);
|
|
1160
|
+
|
|
1161
|
+
return stockOperationModal({
|
|
1162
|
+
...props,
|
|
1163
|
+
items: items,
|
|
1164
|
+
fieldGenerator: stockAssignFields,
|
|
1165
|
+
endpoint: ApiEndpoints.stock_assign,
|
|
1166
|
+
title: t`Assign Stock to Customer`,
|
|
1167
|
+
successMessage: t`Stock assigned to customer`
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
export function useDeleteStockItem(props: StockOperationProps) {
|
|
1172
|
+
return stockOperationModal({
|
|
1173
|
+
...props,
|
|
1174
|
+
fieldGenerator: stockDeleteFields,
|
|
1175
|
+
endpoint: ApiEndpoints.stock_item_list,
|
|
1176
|
+
modalFunc: useDeleteApiFormModal,
|
|
1177
|
+
title: t`Delete Stock Items`,
|
|
1178
|
+
successMessage: t`Stock deleted`
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
export function stockLocationFields(): ApiFormFieldSet {
|
|
1183
|
+
const fields: ApiFormFieldSet = {
|
|
1184
|
+
parent: {
|
|
1185
|
+
description: t`Parent stock location`,
|
|
1186
|
+
required: false
|
|
1187
|
+
},
|
|
1188
|
+
name: {},
|
|
1189
|
+
description: {},
|
|
1190
|
+
structural: {},
|
|
1191
|
+
external: {},
|
|
1192
|
+
custom_icon: {
|
|
1193
|
+
field_type: 'icon'
|
|
1194
|
+
},
|
|
1195
|
+
location_type: {}
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
return fields;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// Construct a set of fields for
|
|
1202
|
+
export function useTestResultFields({
|
|
1203
|
+
partId,
|
|
1204
|
+
itemId,
|
|
1205
|
+
templateId,
|
|
1206
|
+
editing = false,
|
|
1207
|
+
editTemplate = false
|
|
1208
|
+
}: {
|
|
1209
|
+
partId: number;
|
|
1210
|
+
itemId: number;
|
|
1211
|
+
templateId: number | undefined;
|
|
1212
|
+
editing?: boolean;
|
|
1213
|
+
editTemplate?: boolean;
|
|
1214
|
+
}): ApiFormFieldSet {
|
|
1215
|
+
// Valid field choices
|
|
1216
|
+
const [choices, setChoices] = useState<any[]>([]);
|
|
1217
|
+
|
|
1218
|
+
// Field type for the "value" input
|
|
1219
|
+
const [fieldType, setFieldType] = useState<'string' | 'choice'>('string');
|
|
1220
|
+
|
|
1221
|
+
const settings = useGlobalSettingsState();
|
|
1222
|
+
|
|
1223
|
+
const includeTestStation = useMemo(
|
|
1224
|
+
() => settings.isSet('TEST_STATION_DATA'),
|
|
1225
|
+
[settings]
|
|
1226
|
+
);
|
|
1227
|
+
|
|
1228
|
+
return useMemo(() => {
|
|
1229
|
+
const fields: ApiFormFieldSet = {
|
|
1230
|
+
stock_item: {
|
|
1231
|
+
value: itemId,
|
|
1232
|
+
hidden: true
|
|
1233
|
+
},
|
|
1234
|
+
template: {
|
|
1235
|
+
disabled: !editTemplate && !!templateId,
|
|
1236
|
+
filters: {
|
|
1237
|
+
include_inherited: true,
|
|
1238
|
+
part: partId
|
|
1239
|
+
},
|
|
1240
|
+
onValueChange: (value: any, record: any) => {
|
|
1241
|
+
// Adjust the type of the "value" field based on the selected template
|
|
1242
|
+
if (record?.choices) {
|
|
1243
|
+
const _choices: string[] = record.choices.split(',');
|
|
1244
|
+
|
|
1245
|
+
if (_choices.length > 0) {
|
|
1246
|
+
setChoices(
|
|
1247
|
+
_choices.map((choice) => {
|
|
1248
|
+
return {
|
|
1249
|
+
label: choice.trim(),
|
|
1250
|
+
value: choice.trim()
|
|
1251
|
+
};
|
|
1252
|
+
})
|
|
1253
|
+
);
|
|
1254
|
+
setFieldType('choice');
|
|
1255
|
+
} else {
|
|
1256
|
+
setChoices([]);
|
|
1257
|
+
setFieldType('string');
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
},
|
|
1262
|
+
result: {},
|
|
1263
|
+
value: {
|
|
1264
|
+
field_type: fieldType,
|
|
1265
|
+
choices: fieldType === 'choice' ? choices : undefined
|
|
1266
|
+
},
|
|
1267
|
+
attachment: {},
|
|
1268
|
+
notes: {},
|
|
1269
|
+
started_datetime: {
|
|
1270
|
+
hidden: !includeTestStation
|
|
1271
|
+
},
|
|
1272
|
+
finished_datetime: {
|
|
1273
|
+
hidden: !includeTestStation
|
|
1274
|
+
},
|
|
1275
|
+
test_station: {
|
|
1276
|
+
hidden: !includeTestStation
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
if (editing) {
|
|
1281
|
+
// Prevent changing uploaded attachments
|
|
1282
|
+
delete fields.attachment;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return fields;
|
|
1286
|
+
}, [
|
|
1287
|
+
choices,
|
|
1288
|
+
editing,
|
|
1289
|
+
editTemplate,
|
|
1290
|
+
fieldType,
|
|
1291
|
+
partId,
|
|
1292
|
+
itemId,
|
|
1293
|
+
templateId,
|
|
1294
|
+
includeTestStation
|
|
1295
|
+
]);
|
|
1296
|
+
}
|