Receive virtual parts (#11627)

* Handle receive of virtual parts

- Update line item quantity
- Do not add any stock

* Add unit test

* Additional unit test

* UI form improvements

* Add playwright test

* Updated playwright tests
This commit is contained in:
Oliver
2026-03-30 19:10:56 +11:00
committed by GitHub
parent b4f230753f
commit dab4319033
7 changed files with 145 additions and 30 deletions
+23 -13
View File
@@ -1038,6 +1038,29 @@ class PurchaseOrder(TotalPriceMixin, Order):
base_part = supplier_part.part
# Update the line item quantity
line.received += quantity
line_items_to_update.append(line)
# Extract optional serial numbers
serials = item.get('serials', None)
if serials and type(serials) is list and len(serials) > 0:
serialize = True
else:
serialize = False
serials = [None]
if base_part.virtual:
# Virtual parts are not received into stock, so skip the rest of the loop
if serialize:
raise ValidationError(
_('Serial numbers cannot be assigned to virtual parts')
)
continue
stock_location = item.get('location', location) or line.get_destination()
# Calculate the received quantity in base part units
@@ -1052,15 +1075,6 @@ class PurchaseOrder(TotalPriceMixin, Order):
else:
purchase_price = None
# Extract optional serial numbers
serials = item.get('serials', None)
if serials and type(serials) is list and len(serials) > 0:
serialize = True
else:
serialize = False
serials = [None]
# Construct dataset for creating a new StockItem instances
stock_data = {
'part': supplier_part.part,
@@ -1144,10 +1158,6 @@ class PurchaseOrder(TotalPriceMixin, Order):
bulk_create_items.append(new_item)
# Update the line item quantity
line.received += quantity
line_items_to_update.append(line)
# Bulk create new stock items
if len(bulk_create_items) > 0:
stock.models.StockItem.objects.bulk_create(bulk_create_items)