Repository navigation
Description
Please verify that this bug has NOT been raised before.
- I checked and didn't find a similar issue
Describe the bug*
Watch in BugReels (Change Status is set to Damaged at 8:36, merge and the destination are set at 12:17, and the destination shows one OK stock item of 15 at 19:30)
Transferring a whole stock item with a new status and "Merge into existing stock" on merges it into a stock item with the old status. The new status is dropped, so the damaged units are counted as OK stock.
Steps to Reproduce
- Have a part with 10 units at location A with status OK, and a separate stock item of 5 units at location B with status OK.
- Open the 5-unit stock item and choose Transfer Stock.
- Keep the quantity at 5.
- Click Change Status and choose Damaged.
- Switch on "Merge into existing stock".
- Set Location to A and click Submit.
- Open location A's stock items.
Expected behaviour
The 5 units arrive with status Damaged and stay a separate stock item, because the 10 units at A have status OK. can_merge refuses mismatched statuses for that reason.
Actual: location A has one stock item of 15 units with status OK. The 5-unit item is gone. Its "Merged stock items" tracking entry says status Damaged. The request:
POST /api/stock/transfer/ -> 201
{"items": [{"pk": null, "quantity": "5.00000", "batch": "2026-10-19", "status": 55, "merge": true}], "location": 44}
find_merge_target checks the item's current status, not the requested one. For a full-quantity move, the item goes straight into merge_stock_items, and the requested status only reaches the tracking deltas:
InvenTree/src/backend/InvenTree/stock/serializers.py
Lines 2221 to 2262 in ae1f822
| if merge: | |
| target = stock_item.find_merge_target(location) | |
| if target: | |
| merge_kwargs = { | |
| 'location': location, | |
| 'notes': notes, | |
| 'user': request.user, | |
| **kwargs, | |
| } | |
| if quantity < stock_item.quantity: | |
| transfer_deltas = {} | |
| piece = stock_item.splitStock( | |
| quantity, | |
| location, | |
| request.user, | |
| notes=notes, | |
| allow_production=True, | |
| record_tracking=False, | |
| split_transfer_deltas=transfer_deltas, | |
| **kwargs, | |
| ) | |
| if not piece: | |
| continue | |
| merge_kwargs['transfer_deltas'] = transfer_deltas | |
| target.merge_stock_items([piece], **merge_kwargs) | |
| else: | |
| transfer_deltas = {'stockitem': stock_item.pk} | |
| if location: | |
| transfer_deltas['location'] = location.pk | |
| for field_name in StockItem.optional_transfer_fields(): | |
| if field_name in kwargs: | |
| transfer_deltas[field_name] = kwargs[field_name] | |
| merge_kwargs['transfer_deltas'] = transfer_deltas | |
| target.merge_stock_items([stock_item], **merge_kwargs) |
Comparing the requested status, not the current one, when choosing the merge target would fix it. Merge on transfer came in with #12022.
Deployment Method
Other - added info in Steps to Reproduce
Version Information
Reproduced on demo.inventree.org on 2026-10-19 (1.7.0 dev, API 560). The current demo and master (ae1f822) have the same code. Current demo version information:
InvenTree-Version: 1.7.0 dev
API-Version: 562
Commit Hash: 3c644dd
Commit Date: 2026-10-23
Python Version: 3.14.8
Django Version: 5.2.17
Docker Mode: True
Try to reproduce on the demo site
I tried to reproduce
Is the bug reproducible on the demo site?
Reproducible
I have reviewed this report for correctness and filled out all sections.
- I have checked this report. I acknowledge that filing bugs via AI agents without review might lead to being blocked.
This report was drafted with Claude Code (Claude Opus 5.5) and reviewed before filing. The bug was reproduced on the demo, and the cause was checked against the linked source.
Activity
[bug] Fix for merging stock items (inventree#13091)
[bug] Fix for merging stock items (#13091) (#13096)