For Subscription Billing, the Discount field is a custom field and the transaction Amount reflects the Total Amount less the calculated Discount Amount. Discount is not directly related to Quantity or Rate field. Therefore, when a user edits either Quantity or Rate on an existing Invoice created through Subscription Billing then the Amount will no longer apply the Discount. If these fields need to be changed with Discount still applied, then the user needs to delete the Invoice and re-create with the corrected value/s. Another solution is to alter the script to have the Discount applied to Rate instead of Amount.