diff --git a/saas/cart.py b/saas/cart.py index 088ca48d..64c15f7a 100644 --- a/saas/cart.py +++ b/saas/cart.py @@ -68,9 +68,9 @@ def cart_insert_item(request, **kwargs): filter_args = None if sync_on: if filter_args: - filter_args |= Q(sync_on=sync_on) + filter_args |= Q(sync_on__iexact=sync_on) else: - filter_args = Q(sync_on=sync_on) + filter_args = Q(sync_on__iexact=sync_on) if option: if filter_args: filter_args |= Q(option=option) @@ -95,7 +95,8 @@ def cart_insert_item(request, **kwargs): use = template_item.use # Can we use that template? if sync_on: - if template_item.sync_on and template_item.sync_on != sync_on: + if (template_item.sync_on and + template_item.sync_on.lower() != sync_on.lower()): # conflicting sync_on. we cannot use the template. template_item = None if template_item and option: @@ -147,11 +148,14 @@ def cart_insert_item(request, **kwargs): continue if sync_on: item_sync_on = item.get('sync_on') - if item_sync_on and item_sync_on == sync_on: + if (item_sync_on and + item_sync_on.lower() == sync_on.lower()): if not template_item: template_item = item continue - if template_item.get('sync_on') != sync_on: + template_sync_on = template_item.get('sync_on') + if (template_sync_on and + template_sync_on.lower() != sync_on.lower()): # The item matches on sync_on but the template # does not. template_item = item @@ -176,10 +180,12 @@ def cart_insert_item(request, **kwargs): if template_item.get('use') != use: template_item = item continue - if (template_item and - template_item.get('sync_on') == sync_on): - # We already have a template matching on `sync_on`. - continue + if template_item: + template_sync_on = template_item.get('sync_on') + if (template_sync_on and + template_sync_on.lower() == sync_on.lower()): + # We already have a template matching on `sync_on`. + continue # Couldn't match on `sync_on`. next is `option`. if option: item_option = item.get('option') @@ -227,7 +233,8 @@ def cart_insert_item(request, **kwargs): # Can we use that template? if sync_on: template_sync_on = template_item.get('sync_on') - if template_sync_on and template_sync_on != sync_on: + if (template_sync_on and + template_sync_on.lower() != sync_on.lower()): # conflicting sync_on. we cannot use the template. template_item = None if template_item and option: @@ -311,7 +318,7 @@ def session_cart_to_database(request): email != cart_item.email)): continue if (sync_on and (not cart_item.sync_on or - sync_on != cart_item.sync_on)): + sync_on.lower() != cart_item.sync_on.lower())): continue # We found a `CartItem` in the database that was can be # further constrained by the cookie session item. diff --git a/saas/humanize.py b/saas/humanize.py index 4e8347ef..990f3bc1 100644 --- a/saas/humanize.py +++ b/saas/humanize.py @@ -263,9 +263,9 @@ def translate_descr_suffix(descr): pat = r"(a %(percent)s discount)?( and )?"\ r"(%(nb_periods)s %(period_name)s free)?( and )?"\ r"(a %(amount)s off)?"\ + r"( \(code: %(code)s\))?"\ r"(, complimentary of %(payer)s)?"\ - r"(\s*for %(subscriber_full_name)s \(%(sync_on)s\))?"\ - r"( \(code: %(code)s\))?" % REGEXES + r"(\s*for %(subscriber_full_name)s \(%(sync_on)s\))?" % REGEXES look = re.match(pat, descr_suffix) if look: descr_suffix = "" @@ -291,6 +291,9 @@ def translate_descr_suffix(descr): descr_suffix += sep + _(DESCRIBE_SUFFIX_DISCOUNT_CURRENCY) % { 'amount': amount} sep = _(" and ") + code = look.group('code') + if code: + descr_suffix += _(DESCRIBE_SUFFIX_COUPON_APPLIED) % {'code': code} payer = look.group('payer') if payer: descr_suffix += _(", complimentary of %(payer)s") % {'payer': payer} @@ -301,9 +304,6 @@ def translate_descr_suffix(descr): 'subscriber_full_name': subscriber_full_name, 'sync_on': sync_on } - code = look.group('code') - if code: - descr_suffix += _(DESCRIBE_SUFFIX_COUPON_APPLIED) % {'code': code} if descr_suffix: descr += " - %s" % descr_suffix diff --git a/saas/models.py b/saas/models.py index 4ee0ee2a..b53e276d 100644 --- a/saas/models.py +++ b/saas/models.py @@ -777,7 +777,7 @@ def execute_order(self, invoicables, user): if cart_items.exists(): # We are doing a groupBuy for a specified email. bulk_items = cart_items.filter( - sync_on=subscription.organization.email) + sync_on__iexact=subscription.organization.email) if bulk_items.exists(): cart_item = bulk_items.get() else: @@ -2357,9 +2357,13 @@ def to_sync(self, user): Returns charges which have been paid and a 3rd party asked to be notified about. """ - results = self.filter(Q(sync_on=user.username) | Q(sync_on=user.email) - | Q(sync_on__in=get_organization_model().objects.accessible_by(user).values( - 'slug').distinct()), + results = self.filter(Q(sync_on__iexact=user.email) | + # We don't do case-insensitive search here (i.e. `sync_on__in`) + # because we assume the case for sync_on field and username/slug + # are in sync here. + Q(sync_on=user.username) | + Q(sync_on__in=get_organization_model().objects.accessible_by( + user).values('slug').distinct()), charge__state=Charge.DONE, invoice_key__isnull=False) return results