Skip to content

Conversation

@SchrodingersGat
Copy link
Member

@SchrodingersGat SchrodingersGat commented Oct 28, 2025

Implement "generic" parameters, which can be assigned to different model types (not just the "part" model)

Breaking Changes

This PR introduces a set of breaking changes to the "PartParameter" implementation:

  • The PartParameter and PartParameterTemplate models, and associated API endpoints have been removed
  • These have been replacted with a generic Parameter and ParameterTemplate model, which supports parameterized data across multiple model types (not just parts)
  • Any external applictations which interact with the (now defunct) PartParameter API will need to be updated to match the new API interface

Tasks

  • Schema migrations for 2x new models
  • Data migrations for existing models
  • Migrate existing PartParameter objects
  • Migrate existing ManufacturerPartParameter objects
  • Remove PartParameterTemplate model
  • Remove PartParamater model
  • Remove ManufacturerPartParameter model
  • Generate "numeric" values for all existing ManufacturerPartParameter instances
  • Migrate existing CategoryParameter objects
  • API endpoints and serializers
  • django admin integration for 2x new models
  • Refactor signals to rebuild parameter data (part.tasks.rebuild_parameters)
  • Implement parameters property for any class instance which implements parameters (much like attachments)
  • Add field to ParameterTemplate model to tie it to a specific target class type (leave null = generic)
  • Add support for parameters against other class models
  • Remove old database models / serializers / API
  • Reimplement copying parameters from category when part is created
  • Refactor PART_PARAMETER_ENFORCE_UNITS setting
  • Refactor validate_part_parameter method for plugins
  • Reimplement annotation of "parameters" against each applicable model type
  • Refactor to use proper genericforeignkey relations
  • Add reverse annotation of "parameters" against any model type / DRF queryset
  • Add row actions to the "parametric data table" - to add a new parameter to the selected row
  • Implement parametric table view for supplier parts
  • Work out how to handle category parameters in new schema
  • web admin integration for 2x new models
  • Refactor "parameteric parts" table in UI (with filtering based on parameter value
  • Implement parametric table view for manufacturer parts
  • Apply data migrations to demo dataset - Generic parameters demo-dataset#99
  • New generic documentation for parameters and templates in "concepts"
  • Refactor old documentation for part parameters
  • Add generic "concepts" docs for parameters
  • Add generic "concepts" docs for attachments
  • Add new parameter templates and values to demo dataset, for different model types
  • Unit tests for PartParameter migration
  • Update API references in app - Parameters refactor inventree-app#738
  • Ensure that "N + 1" does not occur when annotating "parameters" against a queryset
  • Add unit tests for permission checks against parameter model types
  • Document breaking API change
  • Ensure the custom PartParameterExporter plugin still works
  • Unit tests for data migrations
  • Reimplement per-class hooks for validation / deletion / etc (see PartParameter.check_part_lock)
  • Update API references in web interface
  • Reimplement "import parameters" step in the "part import wizard"
  • Ensure high code coverage for new models
  • Unit tests for ManufacturerPartParameter migration
  • Update API references in python bindings - Generic parameters inventree-python#283

Related Issues

Follow-up PRs

  • Support new API in inventree-kicad - Breaking change - PartParameter afkiwers/inventree_kicad#134
  • Refactor "Attachments" mixin models to follow the cleaner ContentType approach
  • Refactor "ReportTemplate" mixin models to follow the cleaner ContentType approach
  • Refactor "LabelTemplate" mixin models to follow the cleaner ContentType approach
  • Refactor "ImportSession" mixin model to follow the cleaner ContentType approach
  • Refactor "Notes" mixin models to follow the cleaneer ContentType approach

@SchrodingersGat SchrodingersGat added this to the 1.2.0 milestone Oct 28, 2025
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature part Related to Part models api Relates to the API breaking Indicates a major update or change which breaks compatibility refactor migration Data or schema migrations User Interface Related to the frontend / User Interface full-run Always do a full QC CI run labels Oct 28, 2025
@netlify
Copy link

netlify bot commented Oct 28, 2025

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit a24f4a0
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/693149f35f81be0008cd294f

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 89.17710% with 121 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.17%. Comparing base (c443b4e) to head (a24f4a0).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10699      +/-   ##
==========================================
+ Coverage   88.01%   88.17%   +0.15%     
==========================================
  Files        1281     1289       +8     
  Lines       57692    58046     +354     
  Branches     1997     1973      -24     
==========================================
+ Hits        50780    51180     +400     
+ Misses       6415     6375      -40     
+ Partials      497      491       -6     
Flag Coverage Δ
backend 89.47% <81.57%> (-0.16%) ⬇️
migrations 42.48% <43.38%> (+0.08%) ⬆️

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

Components Coverage Δ
Backend Apps 92.03% <86.38%> (+0.02%) ⬆️
Backend General 93.47% <90.92%> (-0.35%) ⬇️
Frontend 70.88% <ø> (+0.50%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

SchrodingersGat and others added 21 commits December 3, 2025 05:57
- Pass "pending" status through to the form
part.0144:
- Add new "enabled" field to PartParameterTemplate model
- Add new ContentType fields to the "PartParameterTemplate" and "PartParameter" models
- Data migration for existing "PartParameter" records

part.0145:
- Set NOT NULL constraints on new fields
- Remove the obsolete "part" field from the "PartParameter" model
- Create new "models" (without moving the existing tables)
- Data migration for PartCataegoryParameterTemplate model
- Remove PartParameterTemplate and PartParameter models
- New models simply point to the old database tables
- Perform schema and data migrations on the old models first (in the part app)
- Swap model references in correct order
@SchrodingersGat SchrodingersGat merged commit fa0d892 into inventree:master Dec 4, 2025
33 of 36 checks passed
@SchrodingersGat SchrodingersGat deleted the generic-parameters branch December 4, 2025 09:42
Comment on lines +156 to +163
ignore_patterns = [
'enum naming encountered a non-optimally resolvable collision for fields named "model_type"'
]

if any(pattern in msg for pattern in ignore_patterns):
return

original_warn(msg, delayed)
Copy link
Contributor

Choose a reason for hiding this comment

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

@SchrodingersGat have you validated that the warning is not substantiated?

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I could determine, it is just an instructional warning because the enumeration could not be explicitly named

@matmair matmair mentioned this pull request Dec 4, 2025
2 tasks
CapnKernel pushed a commit to CapnKernel/InvenTree that referenced this pull request Dec 14, 2025
CapnKernel pushed a commit to CapnKernel/InvenTree that referenced this pull request Dec 14, 2025
* Add ParameterTemplate model

- Data structure duplicated from PartParameterTemplate

* Apply data migration for templates

* Admin integration

* API endpoints for ParameterTemplate

* Scaffolding

* Add validator for ParameterTemplate model type

- Update migrations
- Make Parameter class abstract (for now)
- Validators

* API updates

- Fix options for model_type
- Add API filters

* Add definition for Parameter model

* Add django admin site integration

* Update InvenTreeParameterMixin class

- Fetch queryset of all linked Parameter instances
- Ensure deletion of linked instances

* API endpoints for Parameter instances

* Refactor UI table for parameter templates

* Add comment for later

* Add "enabled" field to ParameterTemplate model

* Add new field to serializer

* Rough-in new table

* Implement generic "parameter" table

* Enable parameters for Company model

* Change migration for part parameter

- Make it "universal"

* Remove code for ManufacturerPartParameter

* Fix for filters

* Add data import for parameter table

* Add verbose name to ParameterTemplate model

* Removed dead API code

* Update global setting

* Fix typos

* Check global setting for unit validation

* Use GenericForeignKey

* Add generic relationship to allow reverse lookups

* Fixes for table structure

* Add custom serializer field for ContentType with choices

* Adds ContentTypeField

- Handles representation of content type
- Provides human-readable options

* Refactor API filtering for endpoints

- Specify ContentType by ID, model or app label

* Revert change to parameters property

* Define GenericRelationship for linking model

* Refactoring some code

* Add a generic way to back-annotate and prefetch parameters for any model type

* Change panel position

* Directly annotate parameters against different model serializers

* remove defunct admin classes

* Run plugin validation against parameter

* Fix prefetching for PartSerializer

* Implement generic "filtering" against queryset

* Implement generic "ordering" by parameter

* Make parametric table generic

* Refactor segmented panels

* Consolidate part table views

* Fix for parametric part table

- Only display parameters for which we know there is a value

* Add parametric tables for company views

* Fix typo in file name

* Prefetch to reduce hits

* Add generic API mixin for filtering and ordering by parameter

* Fix hook for rebuilding template parameters

* Remove serializer

* Remove old models

* Fix code for copying parameters from category

* Implement more parametric tables:

- ManufacturerPart
- SupplierPart
- Fixes and enhancements

* Add parameter support for orders

* Add UI support for parameters against orders

* Update API version

* Update CHANGELOG.md

* Add parameter support for build orders

* Tweak frontend

* Add renderer

* Remove defunct endpoints

* Add migration requirement

* Require contenttypes to be updated

* Update migration

* Try using ID val

* Adjust migration dependencies

* fix params fixture

* fix schema export

* fix modelset

* Fixes for data migration

* tweak table

* Fix for Category Parameters

* Use branch of demo dataset for testing

* Add parameteric build order table

* disable broken imports

* remove old model from ruleset

* correct test

* Table tweaks

* fix test

* Remove old model type

* fix test

* fix test

* Refactor mixin to avoid specifying model type manually

* fix test

* fix resolve name

* remove unneeded import

* Tweak unit testing

* Fix unit test

* Enable bulk-create

* More fixes

* More unit test tweaks

* Enhancements

* Unit test fixes

* Add some migration tests

* Fix admin tests

* Fix part tests

* adapt expectation

* fix remaining typecheck

* Docs updates

* Rearrange models

* fix paramater caching

* fix doc links

* adjust assumption

* Adjust data migration unit tests

* docs fixes

* Fix docs link

* Fixes

* Tweak formatting

* Add doc for setting

* Add metadata view for parameters

* Add metadata view for ParamterTemplate

* Update CHANGELOG file

* Deconflict model_type fields

* Invert key:value

* Revert "Invert key:value"

This reverts commit d555658.

* fix assert

* Update API rev notes

* Initial unit tests for API

* Test parameter create / edit / delete via the API

* Add some more unit tests for the API

* Validate queryset annotation

- Add unit test with large dataset
- Ensure number of queries is fixed
- Fix for prefetching check

* Add breaking change info to CHANGELOG.md

* Ensure that parameters are removed when deleting the linked object

* Enhance type hinting

* Refactor part parameter exporter plugin

- Any model which supports parameters can use this now
- Update documentation

* Improve serializer field

* Adjust unit test

* Reimplement checks for locked parts

* Fix unit test for data migration

* Fix for unit test

* Allow disable edit for ParameterTable

* Fix supplier part import wizard

* Add unit tests for template API filtering

* Add playwright tests for purchasing index

* Add tests for manufacturing index page

* ui tests for sales index

* Add data migration tests for ManufacturerPartParameter

* Pull specific branch for python binding tests

* Specify target migration

* Remove debug statement

* Tweak migration unit tests

* Add options for spectacular

* Add explicit choice options

* Ensure empty string values are converted to None

* Don't use custom branch for python checks

* Fix for migration test

* Fix migration test

* Fix reference target

* Remove duplicate enum in spectactular.py

* Add null choice to custom serializer class

* [UI] Edit shipment details

- Pass "pending" status through to the form

* New migration strategy:

part.0144:
- Add new "enabled" field to PartParameterTemplate model
- Add new ContentType fields to the "PartParameterTemplate" and "PartParameter" models
- Data migration for existing "PartParameter" records

part.0145:
- Set NOT NULL constraints on new fields
- Remove the obsolete "part" field from the "PartParameter" model

* More migration updates:

- Create new "models" (without moving the existing tables)
- Data migration for PartCataegoryParameterTemplate model
- Remove PartParameterTemplate and PartParameter models

* Overhaul of migration strategy

- New models simply point to the old database tables
- Perform schema and data migrations on the old models first (in the part app)
- Swap model references in correct order

* Improve checks for data migrations

* Bug fix for data migration

* Add migration unit test to ensure that primary keys are maintained

* Add playwright test for company parameters

* Rename underlying database tables

* Fixes for migration unit tests

* Revert "Rename underlying database tables"

This reverts commit 477c692.

* Fix for migration sequencing

* Simplify new playwright test

* Remove spectacular collision

* Monkey patch the drf-spectacular warn function

* Do not use custom branch for playwright testing

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API breaking Indicates a major update or change which breaks compatibility enhancement This is an suggested enhancement or new feature full-run Always do a full QC CI run migration Data or schema migrations part Related to Part models refactor User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Adding parameters to POs

2 participants