Cook the tortellini in boiling salted water for about 15 minutes. Drain, quench and let drain well on a sieve. In the meantime peel and finely dice the onions. Wash the thyme, dab dry and pluck the leaves from the stems.
Peel and finely chop the garlic. Wash and clean the mushrooms and halve them as desired. Heat oil in a pot. Sauté onions, garlic, 3/4 of the thyme and mushrooms in it, turning.
Add tomato paste, dust with flour and sauté. Deglaze with strained tomatoes, stock and cream, bring to the boil and season with ketchup, salt, pepper, paprika and sugar. Cut ham into strips and stir into the sauce.
Mix the tortellini and sauce and place in a greased ovenproof dish. Grate the cheese. Sprinkle the tortellini with the sauce and bake in a preheated oven (electric: 200 °C/ gas: level 3) for about 20 minutes.
Sprinkle with remaining thyme and serve garnished with parsley and thyme as desired.