Go to file
Oliver 1f6cd9fc54
[WIP] Data importer (#6911)
* Adds new model for DataImportSession

* Add file extension validation

Expose to admin interface also

* Switch to new 'importer' app

* Refactoring to help prevent circular imports

* Add serializer registry

- Use @register_importer tag for any serializer class

* Cleanup migration file

- Do not use one-time hard-coded values here

* Refactor code into registry.py

* Add validation for the uploaded file

- Must be importable by tablib

* Refactoring

* Adds property to retrieve matching serializer class

* Update helper functions

* Add hook to auto-assign columns on initial creation

* Rename field

* Enforce initial status value

* Add model for individual rows in the data import

* Add DataImportRow model

* Extract data rows as dict

* Update fields

- Remove "progress" field (will be calculated)
- Added "timestamp" field
- Added "complete" field to DataImportRow

* Auto-map column names

- Provide "sensible" default values

* Add API endpoint for DataImportSession

* Offload data import operation

- For large data files this may take a significant amount of time
- Offload it to the background worker process

* Refactor data import code

* Update models

- Add "columns" field to DataImportSession
- Add "errors" field to DataImportRow

* Move field mapping to a new model type

- Simpler validation

* Save "valid" status for each data row

* Include session defaults when validating row data

* Update content_excludes

- Ignore importer models in import/export

* Remove port from ALLOWED_HOST entries

* Skip table events for importer models

* Bug fixes

* Serializer updates

* Add more endpoints

- DataImportColumnMappingList
- DataImportRowList

* further updates:

- Add 'get_api_url' method
- Handle case where

* Expose "available fields" to the DataImportSession serializer

Uses the (already available) inventree metadata middleware

* Add detail endpoints

* Clear existing column mappings

* Add endpoint for accepting column mappings

* Add API endpoint exposing available importer serializers

* Add simple playground area for testing data importer

* Adds simple form to start new import session

- Needs work, file field does not currently function correctly

* data_file is *not* read_only

* Add check for file type

* Remove debug statements

* Refactor column mapping

- Generate mapping for each column
- Remove "columns" field
- Column names are calculated dynamically

* Fix uniqueness requirements on mapping table

* Admin updates

- Prevent deletion of mappings
- Prevent addition of mappings

* API endpoint updates

- Prevent mappings from being deleted
- Prevent mappings from being created

* Update importer drawer

* Add widget for selecting data columns

* UI tweaks

* Delete import session when closing modal

* Allow empty string value

* Complete column mapping

* Adds ability to remove rows

* Adjust drawer specs

* Add column 'description' to serializer

* Add option to hide labels in API form field

* Update column heading

* Fix frontend linting errors

* Revert drawer position

* Return correct type

* Fix shadowing

* Fix f-string

* simplify frontend code

* Move importer app

* Update API version

* Reintroduce export formats

* Add new models to RuleSet

* typescript cleanup

* Typescript cleanup

* Improvement for Switch / boolean field

* Display original row data on popover

* Only display mapped columns

* Add DataExportMixin class

- Replaces existing APIDownloadMixin
- Uses DRF serializers for exporting
- *much* more efficient

* Create new file: importer.mixins.py

* Add new mixin to existing views which support data export

* Better error handling

* Cleanup:

- Remove references to APIDownloadMixin
- Remove download_queryset method
- All now handled by API-based export functionality

* Replace table with InvenTreeTable

- Paginate imported rows
- Data can be searched, ordered,

* Make 'pathstring' fields read-only

* Expose list of valid importer types to the API

* Exclude read-only fields

* Cleanup

* Updates for session model

- Column is now editable on mapping object
- Field is no  longer editable
- Improve admin integration

* Adds new custom hook for controlling data import session

* Refactor column mapping widget

* Refactor ImportDataSelector

* Working on ImportDataSelector component

* Adds method for editing fields in import table

- Cell edit mode
- Row edit mode
- Form submission still needs work!

* Adds background task for removing old import sessions

* Fix api_version.py

* Update src/frontend/src/components/importer/ImportDataSelector.tsx

Co-authored-by: Lukas <76838159+wolflu05@users.noreply.github.com>

* Update model verbose names

* Rename mixin class

* Add serializer mixin classes

- Will allow for fine-tuning of the import/export proces

* @register_importer requires specific mixin

* Check subclass for export

* Fix typos

* Refactor export serializer

- Keep operations local to the class

* Add shim class to process an individual row before exporting it

* Add mixin to existing serializers

* Add export functionality for company serializers

* Adds  placeholder for custom admin class

* Update mantine styling

* spacing -> gap

* Add functionality to pre-process form data before upload

* Remove old references to download_queryset

* Improvements for data import drawer:

- Pin title at top of drawer

* Further improvements

* Fix column selection input

* Formatting improvements

* Use a <Stepper> component for better progress display

* Cleanup text

* Add export-only fields to BuildItem queryset

* Expand "export" fields for BuildItem dataset

* Skip backup and static steps in CI

* Remove hard-coded paths

* Fix for "accept_mapping" method

* Present required fields first on import session

* Add "get_importable_fields" method

* Add method for commiting imported row to database

* Cleanup

* Save "complete" state after row import

* Allow prevention of column caching

* Remove debug statement

* Add basic admin table for import sessions

* Fix for table filter functions

- New mantine version requires string values

* Add filters for import session table

* Remove debug message

* fix for <FilterItem />

* Create new import session from admin page

* Cleanup playground

* Re-open an existing import session

* Memoize cell value

* Update <ImportDataSelector>

* Enable download of build line data

* Add extra detail fields

* Register data importers for the stock app

* Enable download of stock item tracking data

* Register importerrs for "company" app

* Register importers for the "order" app

* Add extra fields to purchase order line item serializer

* Update verbose names for order models

* Cleanup import data table rendering

* Pass session information through to cell renderer

* add separate 'field_overrides' field

* Expose 'field_overrides' to API

* Refactor import field selection

* Use override data if provided

* Fix data extraction

- Ignore columns which are not mapped

* Fix fields.pop

- Provide 'None' argument

* Update import data rendering

* Handle missing / empty column names when importing data

* Bug fixin'

* Update hook

* Adds button to upload data straight to table

* Cache "available_fields"

- Reduces API access time by 85%

* Fix calculation of completed_row_count

* Import individual rows from import session

* Allow import of multiple simultaneous records

* Improve extraction of metadata

- Especially for related fields
- Request object no longer required

* Implement suspended rendering of model instances

* Cleanup

* Implement more columns for StockTable

* Allow stock filtering by packaging field

* Fix "stock_value" column

* Improve metadata extraction

- Handle read_only_fields in Meta
- Handle write_only_fields in Meta

* Increase maximum number of importable rows

* Force data import to run on background worker

* Add export-only fields to StockItemSerializer class

* Data conversion when performing initial import

* Various tweaks

* Fix order of operations for data import

* Rename component

* Allow import/export of more model types

* Fix verbose name

* Import rows as a bulk db operation

* Enable download for PartCategoryTemplateTable

* Update stock item export

* Updates for unit tests

* Remove xls format for now

- Causes some bug in tablib
- Surely xlsx is OK?

* More unit test updates

* Future proof migration

* Updates

* unit tests

* Unit test fix

* Remove 'field_overrides'

- field_defaults will suffice

* Remove 'xls' as download option from frontend

* Add simple unit test for data import

* PUI tweaks

---------

Co-authored-by: Lukas <76838159+wolflu05@users.noreply.github.com>
2024-07-06 18:29:52 +10:00
.devcontainer Cache updates (#7388) 2024-06-02 21:43:31 +10:00
.devops Pin hashes in requirements (#7081) 2024-04-23 17:15:52 +10:00
.github [WIP] Data importer (#6911) 2024-07-06 18:29:52 +10:00
.vscode Code structure refactor (#5582) 2024-04-03 12:16:59 +11:00
assets/images/logo Code structure refactor (#5582) 2024-04-03 12:16:59 +11:00
contrib Package is not checking for already existing installs (#7555) 2024-07-05 09:21:07 +10:00
docs Feat: SSO group sync (#7293) 2024-06-29 20:32:28 +10:00
src [WIP] Data importer (#6911) 2024-07-06 18:29:52 +10:00
.git-blame-ignore-revs Cleanups for refactor (#6933) 2024-04-03 19:59:02 +11:00
.gitattributes fix endline 2022-05-20 13:35:07 +02:00
.gitignore Report printing refactor (#7074) 2024-05-22 10:17:01 +10:00
.pkgr.yml Adjust pkgr.yml (#6608) 2024-03-01 12:49:06 +11:00
.pre-commit-config.yaml Bump pre commit versions (#7255) 2024-06-25 20:52:34 +10:00
codecov.yml More tests for users app (#7479) 2024-06-21 23:49:52 +10:00
CONTRIBUTING.md Bump pre commit versions (#7255) 2024-06-25 20:52:34 +10:00
crowdin.yml Code structure refactor (#5582) 2024-04-03 12:16:59 +11:00
LICENSE Update LICENSE 2022-02-21 22:31:10 +11:00
Procfile Fix typo in Procfile (#7043) 2024-04-16 08:53:03 +10:00
pyproject.toml Bump pre commit versions (#7255) 2024-06-25 20:52:34 +10:00
README.md Feat: SSO group sync (#7293) 2024-06-29 20:32:28 +10:00
readthedocs.yml Code structure refactor (#5582) 2024-04-03 12:16:59 +11:00
RELEASE.md Update broken links (#7019) 2024-04-17 19:42:59 +10:00
requirements.txt Admin shell (#6998) 2024-04-11 21:12:41 +10:00
runtime.txt Add package-based install method (#3743) 2022-10-16 10:14:18 +11:00
SECURITY.md Spelling fix: dates -> days (#3193) 2022-06-14 10:07:48 +10:00
tasks.py [WIP] Data importer (#6911) 2024-07-06 18:29:52 +10:00

InvenTree logo

InvenTree

Open Source Inventory Management System

License: MITGitHub tag (latest SemVer) CI Documentation Status Docker Build OpenSSF Best Practices OpenSSF Scorecard Netlify Status Maintainability Rating

codecov Crowdin GitHub commit activity Docker Pulls

GitHub Org's stars Twitter Follow Subreddit subscribers

View Demo · Documentation · Report Bug · Request Feature

🌟 About the Project

InvenTree is an open-source Inventory Management System which provides powerful low-level stock control and part tracking. The core of the InvenTree system is a Python/Django database backend which provides an admin interface (web-based) and a REST API for interaction with external interfaces and applications. A powerful plugin system provides support for custom applications and extensions.

Check out our website for more details.

🧭 Roadmap

Want to see what we are working on? Check out the roadmap tag and horizon milestone.

🛠️ Integration

InvenTree is designed to be extensible, and provides multiple options for integration with external applications or addition of custom plugins:

👾 Tech Stack

Server
Database
Client
DevOps

🧰 Deployment / Getting Started

There are several options to deploy InvenTree.

Single line install - read the docs for supported distros and details about the function:

wget -qO install.sh https://get.inventree.org && bash install.sh

Refer to the getting started guide for a full set of installation and setup instructions.

📱 Mobile App

InvenTree is supported by a companion mobile app which allows users access to stock control information and functionality.

👋 Contributing

Contributions are welcomed and encouraged. Please help to make this project even better! Refer to the contribution page.

📜 Translation

Native language translation of the InvenTree web application is community contributed via crowdin. Contributions are welcomed and encouraged.

💸 Sponsor

If you use InvenTree and find it to be useful, please consider sponsoring the project.

💎 Acknowledgements

We would like to acknowledge a few special projects:

Find a full list of used third-party libraries in our documentation.

❤️ Support

This project is supported by the following sponsors:

Martin Löper Oliver Lippert Seth Smith SpaceQuest Ltd Appwrite Cabot Technologies Markus Kasten Jess Haynes

With ongoing resources provided by:

Servers by Digital Ocean Deploys by Netlify Translation by Crowdin

⚠️ License

Distributed under the MIT License. See LICENSE.txt for more information.