-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Change order custom status via api #11982
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
base: master
Are you sure you want to change the base?
Changes from all commits
14da87d
3818493
c5a0721
c53c768
7fa5fd4
cd1c817
4e33d9a
74629ed
9e9f2ef
9830f71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,11 +119,19 @@ | |
| ) | ||
|
|
||
| # Human-readable status text (read-only) | ||
| status_text = serializers.CharField(source='get_status_display', read_only=True) | ||
| status_text = serializers.CharField(read_only=True) | ||
|
|
||
| # status field cannot be set directly | ||
| status = serializers.IntegerField(read_only=True, label=_('Order Status')) | ||
|
|
||
| # can be set directly, but must be valid for the current order status | ||
| status_custom_key = serializers.IntegerField( | ||
| label=_('Custom Status Key'), | ||
| help_text=_('Update order status to a custom value for this logical value'), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this set we loose dynamic choice enumeration in the schema description; @SchrodingersGat is that acceptable or should we patch the schema generation mechanism
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been trying to familiarize myself with how this works, but don't quite understand how it broke. It seems like the schema now thinks that the If you can point me in the right direction, I can see if my solution can be implemented in a way that doesn't change this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matmair what would you propose as an alternative?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleting the description or patching our custom schema generator to still add the choices if a description is set on a serializer. |
||
| allow_null=True, | ||
| default=None, | ||
| ) | ||
|
|
||
| # Reference string is *required* | ||
| reference = serializers.CharField(required=True) | ||
|
|
||
|
|
@@ -194,6 +202,31 @@ | |
| self.Meta.model.validate_reference_field(reference) | ||
| return reference | ||
|
|
||
| def validate_status_custom_key(self, value): | ||
| """Validate the status_custom_key field. | ||
|
|
||
| Ensure the custom status key is valid for the logical order status. | ||
| """ | ||
| if value is None: | ||
| return value | ||
|
|
||
| from generic.states.custom import get_logical_value | ||
|
|
||
| if not isinstance(value, int): | ||
| raise ValidationError(_('Custom status key must be an integer')) | ||
|
|
||
| try: | ||
| custom_status = get_logical_value( | ||
| value, model=self.Meta.model._meta.model_name | ||
| ) | ||
| except: | ||
|
Check failure on line 222 in src/backend/InvenTree/order/serializers.py
|
||
| raise ValidationError(_('Invalid custom status key')) | ||
|
|
||
| if custom_status.logical_key is not self.instance.status: | ||
| raise ValidationError(_('Invalid custom status key for this order status')) | ||
|
|
||
| return value | ||
|
|
||
| @staticmethod | ||
| def annotate_queryset(queryset): | ||
| """Add extra information to the queryset.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to result in a N + 1 query problem - each retrieved item will have multiple database hits.
In fact, this problem already exists in the codebase. I'm currently working on a patch for this which I will amend to your branch