Okay, so, I found a couple of typos, and I've fixed those, and this is working for many things.
But not for everything, because it turns out there's a fairly large and complicated set of things in vendors/blesta/pricing which do their own price computations, completely separate from, so far as I can tell, all the price computations used when processing actual invoices. So in a list of services, the field saying "1 month at $125" is generated through fairly complicated nested series of operations on ItemPriceCollections, ItemPrices, UnitPrices, and so on. And that even has hooks for a "DiscountPrice" functionality... But I don't see anything else talking to this.
So, for instance, the total of line items for an invoice is just computed on the fly in SQL, and so far as I know, that's the total actually used for determining whether an invoice is valid. But the estimates for services use this entire different architecture, and I'm not sure how to get another data item into it, such as a flat discount percentage. And it looks like nothing is actually using that functionality yet (?).
So now I'm really confused by what's even happening there.
discount.patch