Skip to content

Feature: Backend scaffolding for Repair Orders (#12064) - #12072

Open
adityakrmishra wants to merge 159 commits into
inventree:masterfrom
adityakrmishra:feature-repair-orders-backend-12064
Open

adityakrmishra wants to merge 159 commits into
inventree:masterfrom
adityakrmishra:feature-repair-orders-backend-12064

Conversation

@adityakrmishra

@adityakrmishra adityakrmishra commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Addresses the backend requirements for #12064.

This PR introduces the initial Django architecture for the new Repair Order feature, integrating it into the order app as discussed.

Additions:

  • Status Codes: Added RepairOrderStatus enumerations.
  • Models: Added RepairOrder, RepairOrderLineItem, and RepairOrderAllocation to order/models.py.
  • API Routing: Implemented DRF serializers and added CRUD ViewSet endpoints to order/api.py.
  • Linting: Validated via ruff.

(Note: Migration files have not been generated in this commit to avoid environment conflicts. Please run manage.py makemigrations order when reviewing.)

Ready for review before we move on to the Mantine UI scaffolding!

closes #12064

@netlify

netlify Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

👷 Deploy request for inventree-web-pui-preview pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ca8d388

@SchrodingersGat

Copy link
Copy Markdown
Member

Code Formatting

As a starting point it looks like your linting is different to our standard.

As per our contributing guide - run this command on your local instance:

invoke dev.setup-dev

This will ensure that any commits will be correctly formatted automatically.

Migration Files

You will need to commit any migration files when changing database models.

Run invoke migrate to generate the necessary migration files, and commit those generated files.

Comment thread src/backend/InvenTree/order/api.py Outdated
Comment on lines +2516 to +2520
class RepairOrderList(ListCreateAPI):
"""API endpoint for accessing a list of RepairOrder objects."""

queryset = models.RepairOrder.objects.all()
serializer_class = serializers.RepairOrderSerializer

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.

I am missing a permissions class here

@matmair matmair added enhancement This is an suggested enhancement or new feature order Related to purchase orders / sales orders api Relates to the API User Interface Related to the frontend / User Interface labels Jun 3, 2026
@matmair matmair added this to the 2.0.0 milestone Jun 3, 2026
@codecov

codecov Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.66390% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.58%. Comparing base (ad534a7) to head (ca8d388).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12072      +/-   ##
==========================================
+ Coverage   90.45%   90.58%   +0.12%     
==========================================
  Files         909      909              
  Lines       84391    85654    +1263     
  Branches     4336     4320      -16     
==========================================
+ Hits        76335    77587    +1252     
- Misses       7036     7053      +17     
+ Partials     1020     1014       -6     
Flag Coverage Δ
backend 94.04% <97.66%> (+0.08%) ⬆️

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

Components Coverage Δ
Backend Apps 94.48% <97.64%> (+0.09%) ⬆️
Backend General 95.09% <100.00%> (+0.07%) ⬆️
Frontend 77.60% <ø> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat SchrodingersGat left a comment

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.

A good start!

Comment thread src/backend/InvenTree/order/models.py Outdated
class RepairOrder(
InvenTree.models.InvenTreeAttachmentMixin,
InvenTree.models.InvenTreeNotesMixin,
InvenTree.models.InvenTreeMetadataModel,

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.

You will need to add a number of other mixin classes here - look at the "BuildOrder" model for reference:

class Build(
    InvenTree.models.PluginValidationMixin,
    report.mixins.InvenTreeReportMixin,
    InvenTree.models.InvenTreeParameterMixin,
    InvenTree.models.InvenTreeAttachmentMixin,
    InvenTree.models.InvenTreeBarcodeMixin,
    InvenTree.models.InvenTreeNotesMixin,
    InvenTree.models.ReferenceIndexingMixin,
    StateTransitionMixin,
    StatusCodeMixin,
    InvenTree.models.MetadataMixin,
    InvenTree.models.InvenTreeTree,
):

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.

Please review and make requested changes

@adityakrmishra

adityakrmishra commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @SchrodingersGat,

Thanks for pointing me to setSettingState. Using that along with adminuser in doCachedLogin fixed the tab timeout, and all the backend, migration, and schema checks are passing now.

I checked the logs for the remaining failure in Chromium 2/4 and Firefox 2/2. The navigation test passes, and Repair Orders - Create and Lifecycle in pui_repair.spec.ts now creates the order and loads the detail page, but fails at line 64:

await page.getByText('Pending').waitFor();

Playwright fails with a strict mode error because getByText('Pending') matches two elements on the page (the header badge and the badge inside Order Details). On the automatic retry, line 55 (page.getByText('MAST | Master Assembly').click()) times out because the modal fields below the part input intercept the pointer click.

@matmair

matmair commented Nov 2, 2026

Copy link
Copy Markdown
Member

@adityakrmishra you can either use the Playwright tools or the report attached to the run (with traces) to check which exact match would work to pass this too

@SchrodingersGat

Copy link
Copy Markdown
Member

Playwright fails with a strict mode error because getByText('Pending') matches two elements on the page

You can instead use getByText('Pending').first()

@SchrodingersGat SchrodingersGat modified the milestones: 2.0.0, 1.8.0 Nov 3, 2026
- Reject allocation of stock which is not in stock (e.g. quarantined,
  delivered to a customer, or installed in another item). This is also
  checked when stock is consumed on completion, so stock which became
  unavailable after allocation blocks completion instead of being consumed.
- Reject serialized stock: StockItem.take_stock() cannot remove serialized
  items, so such an allocation prevented the order from being completed.
- Skip serialized stock in auto-allocation, and filter it out of the
  allocation form.
- Document the allocation rules.
@transmogrify-cell

Copy link
Copy Markdown

I found two stock allocation issues in the current branch and opened a fix against it: adityakrmishra#1

  1. RepairOrderAllocation.clean() doesn't check item.in_stock, so quarantined stock, stock delivered to a customer, or stock installed in another item can be allocated through the API, and is then deducted when the order is completed.
  2. Serialized stock passes allocation validation (and is selected by auto-allocate), but StockItem.take_stock() refuses serialized items. Completing the order then fails with "Failed to consume repair order stock" and the order stays In Progress.

The fix rejects both at allocation time (and re-checks on completion, with a full rollback), skips serialized stock in auto-allocate, and adds two regression tests. No model or migration changes.

Actually supporting serialized replacement parts still needs a decision on where the consumed item should go (e.g. a consumed_by-style link to the repair order, or installing it into the repaired unit).

transmogrify-cell and others added 6 commits November 10, 2026 23:31
Serialized stock is no longer rejected. As for a build order, a serialized
item allocated to a repair order is marked as consumed by the order when it
is completed, instead of being reduced in quantity.

- Add StockItem.consumed_by_repair, excluded from in-stock stock
- Mark serialized items as consumed (and clear the location) on completion
- Serialized allocations must have a quantity of 1
- Auto-allocation includes serialized stock again (whole items only)
- Clear consumed_by_repair when an item is returned to stock
- Expose the field in the stock API, serializer and admin
- Show the consuming repair order on the stock item page
- Update tests and docs
…stock

Repair orders: consume serialized stock, and only allow available stock to be allocated
@adityakrmishra

Copy link
Copy Markdown
Contributor Author

@SchrodingersGat @matmair synced with master and bumped api_version to v582 in f979b44.

The only two failures look like unrelated flakes (Postgres hit 0.75s on test_consume_many_lines, and Firefox timed out on pui_admin.spec.ts). Could you re-run those two jobs when you get a chance? Otherwise this should be ready for review.

@adityakrmishra

Copy link
Copy Markdown
Contributor Author

@SchrodingersGat merged master in 358cd76 and fixed a query count failure in test_bulk_remove_query_benchmark in ca8d388 (batched the row lock and used bulk_allocation_count() in StockRemoveSerializer.save(), since the extra repair allocation count combined with 939df60 pushed it over 950 queries.

All four DB suites and Chromium 1-4 are green now. The two Firefox failures look unrelated (pui_part.spec.ts saw leftover SN61526 stock after pui_sales.spec.ts flaked on retry 1, and pui_plugins.spec.ts got a 404 on my-custom-plugin/Panel.js). Could you re-run those two Firefox jobs when you get a chance??

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 order Related to purchase orders / sales orders User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Repair orders

4 participants