inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.34k stars 786 forks source link

[Refactor] Custom states #8438

Open SchrodingersGat opened 2 weeks ago

SchrodingersGat commented 2 weeks ago

This PR is an update to the "custom states" functionality, to improve usability and extend user interface integration

Tasks

netlify[bot] commented 2 weeks ago

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

Name Link
Latest commit 8cbe376b52f5464c62b99b1a4ffff44b66247d56
Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/673f1ed7a63a2a00085ee864
SchrodingersGat commented 2 weeks ago

@matmair I have been looking at the implementation of custom states and there are a few areas which I think can be cleaned up a bit.

One question I have is: what is the value of the model (ContentType) field on the InvenTreeCustomUserStateModel model? We already map to a status group, which implies a given model type. I don't see the value of having a separate field (which the user has to know how to fill in) - which can conflict with the specified statuscode.

I would suggest that we remove the model field and rely on the reference_status field to perform this functionality

matmair commented 2 weeks ago

@SchrodingersGat there is only an implicit link between status groups and models. When you start shipping custom models in plugins and using custom states there you need some way to prefilter possible selections.

SchrodingersGat commented 2 weeks ago

I don't understand the use case here - in what circumstance would you want to make a custom state which overrides a BuildStatus code, but links to a SalesOrderShipment model? (for example)

matmair commented 2 weeks ago

The use case is enabling order when you have 40+ state groups and need to filter to manage them. If you see no value you can remove this and I will patch my custom fork for support, it seems anyway like I will never be able to use upstream.

There is no reliable link between a state named "SomeModelStatus" and the model "SomeModel" - especially with possible model name collisions between (3rd party) apps.

wolflu05 commented 2 weeks ago

(Just a question, no opinion here, I just want to understand your design choice)

Do you have any example scenario where custom states and models are in a relationship other than n:1? (E.g. the same custom state is assigned to multiple models. If not, doesn't that say that each custom state has only one model, which implicitly means there is a reliable link between a state and the model.

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 84.62%. Comparing base (01aa8bb) to head (8cbe376). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #8438 +/- ## ========================================== + Coverage 84.60% 84.62% +0.02% ========================================== Files 1178 1178 Lines 53607 53509 -98 Branches 2026 2022 -4 ========================================== - Hits 45353 45282 -71 + Misses 7732 7707 -25 + Partials 522 520 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features:

matmair commented 1 week ago

Implicit is the key here; there is no reliable way to map a custom state to a model, thus automation that needs to make this link will not be able to function anymore if it is removed. I do not rely on implicit mapping in my business-critical LoB apps.