Skip to content

[Enhancement] Import by natural key fields#11288

Open
SchrodingersGat wants to merge 16 commits intoinventree:masterfrom
SchrodingersGat:import-pk-field
Open

[Enhancement] Import by natural key fields#11288
SchrodingersGat wants to merge 16 commits intoinventree:masterfrom
SchrodingersGat:import-pk-field

Conversation

@SchrodingersGat
Copy link
Member

@SchrodingersGat SchrodingersGat commented Feb 11, 2026

This PR allows for data importing by "natural key" fields on related models. Instead of forcing data import by primary key (pk) value only, other fields can be used for lookup.

Examples

  • Lookup 'Part' by IPN
  • Lookup 'SupplierPart' by SKU
  • Lookup 'SalesOrder' by reference

Related Issues

TODO

  • Support wider range of models with natural keys
  • Additional unit testing for data import with natural keys
  • Adversarial unit testing with malformed / improper data
  • Updated playwright tests
  • Enhanced documentation around data import

@SchrodingersGat SchrodingersGat added this to the 1.3.0 milestone Feb 11, 2026
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature import / export Data importing, exporting and processing feature full-run Always do a full QC CI run labels Feb 11, 2026
@netlify
Copy link

netlify bot commented Feb 11, 2026

Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit ee9394c
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/699669402278a60008062381
😎 Deploy Preview https://deploy-preview-11288--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 93 (🟢 up 1 from production)
Accessibility: 81 (no change from production)
Best Practices: 100 (no change from production)
SEO: 78 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces natural key field support for data imports in InvenTree, allowing related models to be referenced by human-readable identifiers (like IPN, SKU, MPN) instead of requiring primary key values. This enhancement makes importing data from external sources more intuitive and reduces the need for manual ID lookups.

Changes:

  • Added lookup_related_field method to perform natural key lookups on related fields during import
  • Added get_related_model method to retrieve related model classes for field lookups
  • Defined IMPORT_ID_FIELDS on multiple models (Part, PartCategory, PartTestTemplate, Company, ManufacturerPart, SupplierPart, Order, Build) to specify which fields can be used for natural key lookups

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/backend/InvenTree/importer/models.py Core implementation of natural key lookup functionality with lookup_related_field and get_related_model methods
src/backend/InvenTree/part/models.py Added IMPORT_ID_FIELDS for Part, PartCategory, and PartTestTemplate models
src/backend/InvenTree/company/models.py Added IMPORT_ID_FIELDS for Company, ManufacturerPart, and SupplierPart models
src/backend/InvenTree/order/models.py Added IMPORT_ID_FIELDS to abstract Order model
src/backend/InvenTree/build/models.py Added IMPORT_ID_FIELDS to Build model

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 39.62264% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.00%. Comparing base (a4a3990) to head (ee9394c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11288      +/-   ##
==========================================
- Coverage   88.04%   88.00%   -0.04%     
==========================================
  Files        1292     1292              
  Lines       58533    58586      +53     
  Branches     1943     1943              
==========================================
+ Hits        51533    51557      +24     
- Misses       6516     6545      +29     
  Partials      484      484              
Flag Coverage Δ
backend 89.20% <39.62%> (-0.05%) ⬇️
migrations 42.25% <30.18%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 91.72% <37.25%> (-0.08%) ⬇️
Backend General 93.38% <100.00%> (+<0.01%) ⬆️
Frontend 70.88% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an suggested enhancement or new feature feature full-run Always do a full QC CI run import / export Data importing, exporting and processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Add IPN as matching field for BoM import [Importer] Natural Key Support

1 participant

Comments