Skip to content

Change order custom status via api#11982

Open
johnluetke wants to merge 10 commits into
inventree:masterfrom
johnluetke:feature/change-order-custom-status-via-api
Open

Change order custom status via api#11982
johnluetke wants to merge 10 commits into
inventree:masterfrom
johnluetke:feature/change-order-custom-status-via-api

Conversation

@johnluetke
Copy link
Copy Markdown

Fixes #11927

As discussed in the issue, an order's custom status key can be updated via the API.

Validation has been added to ensure that the custom_status_key value is aligned to the current logical state of the order.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 21, 2026

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

Name Link
🔨 Latest commit 9830f71
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a1b5783aa7d9d00087c5a82

@johnluetke johnluetke force-pushed the feature/change-order-custom-status-via-api branch from 8c299e9 to 37783d2 Compare May 21, 2026 21:39
@SchrodingersGat SchrodingersGat added this to the 1.4.0 milestone May 21, 2026
@SchrodingersGat SchrodingersGat added the api Relates to the API label May 21, 2026
@SchrodingersGat
Copy link
Copy Markdown
Member

@johnluetke nice clean implementation :)

Copy link
Copy Markdown
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

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

Looks good;
there are a few formatting things, those could be fixed with pre-commit or prek; I will submit them shortly

# 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'),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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 status and custom_status_key fields are more tightly coupled now?

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@matmair what would you propose as an alternative?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.43%. Comparing base (914cd72) to head (9830f71).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11982   +/-   ##
=======================================
  Coverage   91.42%   91.43%           
=======================================
  Files         974      974           
  Lines       51915    51961   +46     
=======================================
+ Hits        47465    47512   +47     
+ Misses       4450     4449    -1     
Flag Coverage Δ
backend 90.44% <98.18%> (+0.01%) ⬆️

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

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

@johnluetke johnluetke force-pushed the feature/change-order-custom-status-via-api branch from 423a9bf to b1a0243 Compare May 22, 2026 18:09
johnluetke and others added 4 commits May 25, 2026 22:19
Refactor `custom_status_key` to be writable via the API and validate that the proposed value is valid for the current order status
@johnluetke johnluetke force-pushed the feature/change-order-custom-status-via-api branch from b1a0243 to c53c768 Compare May 26, 2026 03:19
@SchrodingersGat
Copy link
Copy Markdown
Member

@johnluetke you will need to add a new entry into InvenTree/api_version.py because the API surface has changed.

get_logical_value as get_custom_state_logical_value,
)

custom_status = get_custom_state_logical_value(
Copy link
Copy Markdown
Member

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

@SchrodingersGat
Copy link
Copy Markdown
Member

@johnluetke I have addressed the mentioned query issue, which has unfortunately introduced some conflicts here, but they should be minor.

Please review the changes I made in #12055 - you may have to adjust your approach here slightly

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

Labels

api Relates to the API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PurchaseOrder PATCH accepts status_custom_key, but does not persist valid custom status

3 participants