def test_deallocate_stock_many_allocations(order_line_with_allocation_in_many_stocks,): order_line = order_line_with_allocation_in_many_stocks deallocate_stock(order_line, 3) allocations = order_line.allocations.all() assert allocations[0].quantity_allocated == 0 assert allocations[1].quantity_allocated == 0
def test_deallocate_stock_partially(allocation): stock = allocation.stock stock.quantity = 100 stock.save(update_fields=["quantity"]) allocation.quantity_allocated = 80 allocation.save(update_fields=["quantity_allocated"]) deallocate_stock(allocation.order_line, 50) stock.refresh_from_db() assert stock.quantity == 100 allocation.refresh_from_db() assert allocation.quantity_allocated == 30