For some reason the average costing qty doesn't always end up correctly. To prevent the average costing to run wild in cases when the qty goes below zero an exception called AverageCostingNegativeQtyException has been created.
This exception is helpful when finding errors, but it's not at all helpful to the user who just wants the accounting to be done.
A suggestion is to remove these exceptions and just silently (or logging) adjust qty to zero when the qty would go below zero (which we know is wrong).
Closing as potential idea, however this requires discussion as probably it can affect negatively the costing - the exception was added because when arriving to negative inventories in average costing methods can create big issues that are really hard to solve later.
Patch is broken as bitbucket closed mercurial repositories.