mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-18 06:04:44 +00:00
[bug] Count transfer order allocations when validating build items (#13287)
BuildItem.check_allocated_quantity() summed build and sales order allocations but not transfer order allocations, so stock that was fully allocated to an open transfer order could be allocated again to a build order via the API (POST /api/build/item/). Include transfer_order_allocation_count() in the check, matching StockItem.allocation_count() and bulk_allocation_count(). Fixes #13286
This commit is contained in:
1 parent
f4f5caae2c
commit
3572714f5f
2 files changed
+31
-2
No files matched your search
@@ -2469,8 +2469,16 @@ class BuildItem(InvenTree.models.InvenTreeMetadataModel):
|
||||
sales_allocation_count = decimal.Decimal(
|
||||
self.stock_item.sales_order_allocation_count()
|
||||
)
|
||||
transfer_allocation_count = decimal.Decimal(
|
||||
self.stock_item.transfer_order_allocation_count()
|
||||
)
|
||||
|
||||
total_allocation = build_allocation_count + sales_allocation_count + quantity
|
||||
total_allocation = (
|
||||
build_allocation_count
|
||||
+ sales_allocation_count
|
||||
+ transfer_allocation_count
|
||||
+ quantity
|
||||
)
|
||||
|
||||
if total_allocation > available:
|
||||
error = {'quantity': _('Stock item is over-allocated')}
|
||||
|
||||
@@ -33,7 +33,13 @@ from InvenTree.unit_test import (
|
||||
findOffloadedTask,
|
||||
stock_history_count,
|
||||
)
|
||||
from order.models import PurchaseOrder, PurchaseOrderLineItem
|
||||
from order.models import (
|
||||
PurchaseOrder,
|
||||
PurchaseOrderLineItem,
|
||||
TransferOrder,
|
||||
TransferOrderAllocation,
|
||||
TransferOrderLineItem,
|
||||
)
|
||||
from part.models import BomItem, BomItemSubstitute, Part, PartTestTemplate
|
||||
from stock.models import StockItem, StockItemTestResult, StockLocation
|
||||
from stock.status_codes import StockStatus
|
||||
@@ -352,6 +358,21 @@ class BuildTest(BuildTestBase):
|
||||
with self.assertRaises(ValidationError):
|
||||
b.clean()
|
||||
|
||||
# Stock which is fully allocated to a transfer order is not available
|
||||
item = StockItem.objects.create(part=self.sub_part_1, quantity=10)
|
||||
to = TransferOrder.objects.create(reference='TO-9999')
|
||||
to_line = TransferOrderLineItem.objects.create(
|
||||
order=to, part=self.sub_part_1, quantity=10
|
||||
)
|
||||
TransferOrderAllocation.objects.create(line=to_line, item=item, quantity=10)
|
||||
|
||||
b = BuildItem(stock_item=item, build_line=self.line_1, quantity=10)
|
||||
|
||||
with self.assertRaises(ValidationError) as err:
|
||||
b.clean()
|
||||
|
||||
self.assertIn('Stock item is over-allocated', str(err.exception))
|
||||
|
||||
# Ok, what about we make one that does *not* fail?
|
||||
b = BuildItem(
|
||||
stock_item=self.stock_1_2,
|
||||
|
||||
Reference in new issue
Block a user