Jump to content

[Patch] Add discounts for line items


seebs

Recommended Posts

This is NOT production-ready, but this is what I've got going so far.

In particular: I don't really understand the db migration tasks, or how I would create a migration and hint for it to be run, so right now if you want to use this, you'll have to manually add discount fields to services, service_options, invoice_lines, and invoice_recur_lines. (In all cases, any-old-int type should be fine.)

What this is supposed to do: Allow per-item discounting. This is distinct from coupons in a couple of ways. One is that the discount can be distinct for each package option in a package. Another is that the discount is actually preserved as a trait of the line item, rather than being computed statically and stored as a separate line item. So if something changes that would change the cost of a given line (pricing or quantity, for instance), the discount reflects that.

I haven't fully tested this, I don't think I've gone through the recurring line item use case at all, and I haven't figured out all the GUI elements. I'd quite like to see this get merged into core, or something like it, and I'm aware that it'll need significant cleanup before that would be plausible. But I want to get it out there for people to look at. (I think @Tyson might be the person to look at something like this?)

It's a patch, not a plugin, because plugins can't alter invoice pricing computations.

discount.patch

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...