hasgeek / boxoffice

Ticketing
GNU Affero General Public License v3.0
10 stars 5 forks source link

Uniqueness of coupon code #290

Open iambibhas opened 5 years ago

iambibhas commented 5 years ago

Right now DiscountCoupon.code are unique only inside the same DiscountPolicy. But here in this bit we assume that coupon codes are unique globally. Which caused couple of failures when we created couple of coupon codes with same name as some old coupon codes.

So there is a confusion about the uniqueness of coupon codes. Are they unique -

  1. within a discount policy
  2. across multiple discount policies but within a single item (as Item links to multiple discount policies)
  3. globally, across all discount policies

We'll need to update our logic accordingly.

/cc @jace @vidya-ram

jace commented 5 years ago

Code needs to be unique to an ItemCollection. This requires two fixes:

  1. Enforce that unique constraint when creating codes (may require a PostgreSQL functional index).
  2. Join to an ItemCollection when looking up a code.