Bug 23442 introduces a method of applying a discount/refund to an accountline debt and it enforces that a refund may not exceed the original amount owed on the accountline. However, there's nothing to prevent multiple refunds/discounts being applied to the same line and as such the combined total for all refund against that line should be used to prevent refunding more than the original owed amount instead.
Folded into bug 23442 submission.. marking as duplicate. *** This bug has been marked as a duplicate of bug 23442 ***