Skip to content

Saleor Core: the high performance, composable, headless commerce API.

populateDB - align stock.allocated_quantity with value from allocations (#16903)

Maciej Korycinskie943173e5793
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index e75fb4cc64..af88e7c8f8 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -740,15 +740,17 @@ def create_fulfillments(order):
fulfillment, _ = Fulfillment.objects.get_or_create(order=order)
quantity = random.randrange(0, line.quantity) + 1
allocation = line.allocations.get()
- fulfillment.lines.create(
- order_line=line, quantity=quantity, stock=allocation.stock
- )
+ stock = allocation.stock
+ fulfillment.lines.create(order_line=line, quantity=quantity, stock=stock)
line.quantity_fulfilled = quantity
line.save(update_fields=["quantity_fulfilled"])
allocation.quantity_allocated = F("quantity_allocated") - quantity
allocation.save(update_fields=["quantity_allocated"])
+ stock.quantity_allocated = F("quantity_allocated") - quantity
+ stock.save(update_fields=["quantity_allocated"])
+
update_order_status(order)