Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User defined states #7862

Merged
merged 69 commits into from
Aug 21, 2024

Conversation

matmair
Copy link
Member

@matmair matmair commented Aug 12, 2024

This PR adds the option to use user-defined states to models that use generic states.

For this, the model must be adapted to use the new InvenTreeCustomStatusModelField and the model's serializers must inherit InvenTreeCustomStatusSerializerMixin. The default behaviour of the serializer field is not changed but a new field is made available: {field_name}_custom_key. Custom states must always map to a logical key that points to the business logic. Custom states require unique keys that can not shadow logical keys. In theory, a model could make use of multiple fields with multiple custom states. This is not unit-tested with this PR but the code is developed with it in mind.

This PR does not change business logic but contains various frontend changes to render the custom field value instead of the (business) logic value. Both CUI and PUI were adapted to support the states. Colours for states now support enums (I would encourage usage of the enum)

Most API calls to serializers that use custom states experience 1-2 more DB calls due to the lookup of custom states. There is no caching in this PR implemented as consistency checks between different workers presented to be difficult.

ToDo

Included changes that are not strictly custom states:

  • Adds filtering for contettypes API
  • Adds contenttype model to PUI generic instance/form rendering
  • Moves generic state API URL definitions to src/backend/InvenTree/generic/states

Closes #4289

@matmair matmair added enhancement This is an suggested enhancement or new feature user interface User interface api Relates to the API roadmap This is a roadmap feature with no immediate plans for implementation Platform UI Related to the React based User Interface labels Aug 12, 2024
@matmair
Copy link
Member Author

matmair commented Aug 16, 2024

This is technically done, I will try to finish the docs by the end of the week.

@matmair matmair marked this pull request as ready for review August 16, 2024 00:47
@matmair
Copy link
Member Author

matmair commented Aug 17, 2024

@SchrodingersGat this is ready for review and merge. I don't know if we should backport it though as I am unsure how the API revision should be ported to 0.16.x.

It would be cool if we could get it into 0.16.x but probably more hassle than it is worth.

@SchrodingersGat
Copy link
Member

@matmair I think that given the amount of significant change here, we should let it have a round of testing in the 0.17.x cycle before pushing it out to stable. Happy with that?

@matmair matmair modified the milestones: 0.16.0, 0.17.0 Aug 19, 2024
@matmair
Copy link
Member Author

matmair commented Aug 19, 2024

@SchrodingersGat i have changed the target

@matmair
Copy link
Member Author

matmair commented Aug 21, 2024

I have adjusted the api_version so that this can be merged after #7520

@SchrodingersGat
Copy link
Member

Thanks for the hard work on this one @matmair - due to the large number of changes here we will need to monitor closely until the 0.17.x release

@SchrodingersGat SchrodingersGat merged commit d5086b2 into inventree:master Aug 21, 2024
26 checks passed
@SchrodingersGat SchrodingersGat deleted the custom-user-defined-states branch August 21, 2024 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Relates to the API enhancement This is an suggested enhancement or new feature Platform UI Related to the React based User Interface roadmap This is a roadmap feature with no immediate plans for implementation user interface User interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Stock Status
3 participants