Skip to content

Fix order allocation variant validation logic and serializer read_only_fields - #12738

Merged
SchrodingersGat merged 8 commits into
inventree:masterfrom
bhumin18:fix-order-allocation-validation-and-serializers
Sep 2, 2026
Merged

SchrodingersGat merged 8 commits into
inventree:masterfrom
bhumin18:fix-order-allocation-validation-and-serializers

Conversation

@bhumin18

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a data validation logic bug in order allocation models and cleans up serializer read_only_fields definitions:

  1. order/models.py (SalesOrderAllocation.clean() & TransferOrderAllocation.clean()):

    • Fixed the variant check from self.line.part not in variants to self.item.part not in variants.
    • Why this matters: Because variants = self.line.part.get_descendants(include_self=True), checking self.line.part not in variants was always False, which allowed allocating completely unrelated stock items to order line items without triggering the validation error. Now, only the required part or its valid descendant variants can be allocated.
  2. order/serializers.py (SalesOrderAllocationSerializer & TransferOrderAllocationSerializer):

    • Removed the erroneous empty string '' from read_only_fields = ['line'].
  3. order/test_api.py (OrderAllocationValidationTest):

    • Added unit tests verifying that allocating unrelated stock items raises ValidationError, while allocating valid variant stock items succeeds.

@netlify

netlify Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit 9ac5afd
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a980b5031f24c0008775e08

@matmair

matmair commented Aug 29, 2026

Copy link
Copy Markdown
Member

There are a lot of style changed here that make no sense; make sure to read the contributions guide - especially regarding formatting https://docs.inventree.org/en/stable/develop/contributing/

@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.14%. Comparing base (f9f9f74) to head (9ac5afd).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12738      +/-   ##
==========================================
+ Coverage   87.08%   87.14%   +0.06%     
==========================================
  Files        1483     1481       -2     
  Lines      100213    99757     -456     
  Branches    11609    11436     -173     
==========================================
- Hits        87270    86937     -333     
+ Misses      12878    12755     -123     
  Partials       65       65              
Flag Coverage Δ
backend 91.10% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
Backend Apps 92.28% <100.00%> (-0.10%) ⬇️
Backend General 93.77% <ø> (-0.76%) ⬇️
Frontend 79.95% <ø> (+0.19%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed backport Apply this label to a PR to enable auto-backport action backport-to-1.5.x labels Sep 2, 2026
@SchrodingersGat SchrodingersGat added this to the 1.6.0 milestone Sep 2, 2026
@SchrodingersGat

Copy link
Copy Markdown
Member

@bhumin18 thank you for cleaning up the PR, much easier to review it now.

This is a good catch, thanks for submitting a fix for this.

@SchrodingersGat
SchrodingersGat merged commit bb151dc into inventree:master Sep 2, 2026
45 checks passed
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

💔 All backports failed

Status Branch Result
❌ 1.5.x Backport failed because of merge conflicts

You might need to backport the following PRs to 1.5.x:
- Fix 500 errors for transitions (#12678)

Manual backport

To create the backport manually run:

backport --pr 12738

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

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

Labels

backport Apply this label to a PR to enable auto-backport action backport-to-1.5.x bug Identifies a bug which needs to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants