QuickBooks Online only allows the first-in-first-out (FIFO) method of calculating cost of goods sold (COGS) and QuickBooks Desktop allows you to choose between FIFO and average cost.
With the FIFO method, any create or update operation on a sales receipt with inventory items will have to update the cost of every single transaction afterwards with that those same inventory items.
This can take a really long time especially if you have a sales receipt with many inventory items or if you're inserting a sales receipt before in time compared to other sales receipt.
My recommendation is to keep your books up to date as much as possible to avoid inserting sales receipts before others. That way QuickBooks won't have to do much recalculation of cost of goods sold.
If you're using QuickBooks Desktop, an easy way is to simply switch to the average cost of goods sold calculation, but that may not be what you want.
Lastly, another reason could be that you have negative quantities on hand. Therefore, QuickBooks is confused because it doesn't know how to assign the cost of goods sold to that inventory item. It's worth checking that all your quantities on hand for inventory items are greater than or equal to 0 and adjusting if necessary.
Make sure you also add all your purchase transactions for when you receive inventory. This will keep your inventory at the correct levels.