示例#1
0
    def get_warning(self):
        """
        Return a warning message about this basket line if one is applicable

        This could be things like the price has changed
        """
        if isinstance(self.purchase_info.availability, Unavailable):
            msg = "'%(product)s' is no longer available"
            return _(msg) % {'product': self.product.get_title()}

        if not self.price_incl_tax:
            return
        if not self.purchase_info.price.is_tax_known:
            return

        # Compare current price to price when added to basket
        current_price_incl_tax = self.purchase_info.price.incl_tax
        if current_price_incl_tax != self.price_incl_tax:
            product_prices = {
                'product': self.product.get_title(),
                'old_price': currency(self.price_incl_tax),
                'new_price': currency(current_price_incl_tax)
            }
            if current_price_incl_tax > self.price_incl_tax:
                warning = _("The price of '%(product)s' has increased from"
                            " %(old_price)s to %(new_price)s since you added"
                            " it to your basket")
                return warning % product_prices
            else:
                warning = _("The price of '%(product)s' has decreased from"
                            " %(old_price)s to %(new_price)s since you added"
                            " it to your basket")
                return warning % product_prices
示例#2
0
 def clean_amount(self):
     amt = self.cleaned_data.get('amount')
     max_allocation = self.max_allocation
     if amt > max_allocation:
         raise forms.ValidationError(
             _("The maximum allocation is %s") % currency(max_allocation))
     return amt
示例#3
0
 def clean_amount(self):
     amt = self.cleaned_data['amount']
     max_amount = self.account.balance
     if amt > max_amount:
         raise forms.ValidationError(
             _("The account has only %s") % (currency(max_amount)))
     return amt
示例#4
0
 def __str__(self):
     description = _("Allocation of %(amount)s from type %(type)s") % {
         'amount': currency(self.amount_allocated, self.currency),
         'type': self.source_type
     }
     if self.reference:
         description += _(" (reference: %s)") % self.reference
     return description
示例#5
0
 def clean_amount(self):
     amt = self.cleaned_data['amount']
     if hasattr(settings, 'ACCOUNTS_MAX_ACCOUNT_VALUE'):
         max_amount = (settings.ACCOUNTS_MAX_ACCOUNT_VALUE -
                       self.account.balance)
         if amt > max_amount:
             raise forms.ValidationError(
                 _("The maximum permitted top-up amount is %s") %
                 (currency(max_amount)))
     return amt
示例#6
0
 def form_valid(self, form):
     account = self.object
     amount = form.cleaned_data['amount']
     try:
         facade.transfer(form.get_source_account(), account, amount,
                         user=self.request.user,
                         description=_("Top-up account"))
     except exceptions.AccountException as e:
         messages.error(self.request,
                        _("Unable to top-up account: %s") % e)
     else:
         messages.success(
             self.request, _("%s added to account") % currency(amount))
     return http.HttpResponseRedirect(reverse('accounts-detail',
                                              kwargs={'pk': account.id}))
示例#7
0
    def availability_restrictions(self):  # noqa (too complex (15))
        restrictions = []
        if self.is_suspended:
            restrictions.append({
                'description': _("Offer is suspended"),
                'is_satisfied': False})

        if self.max_global_applications:
            remaining = self.max_global_applications - self.num_applications
            desc = _("Limited to %(total)d uses (%(remainder)d remaining)") \
                % {'total': self.max_global_applications,
                   'remainder': remaining}
            restrictions.append({'description': desc,
                                 'is_satisfied': remaining > 0})

        if self.max_user_applications:
            if self.max_user_applications == 1:
                desc = _("Limited to 1 use per user")
            else:
                desc = _("Limited to %(total)d uses per user") \
                    % {'total': self.max_user_applications}
            restrictions.append({'description': desc,
                                 'is_satisfied': True})

        if self.max_basket_applications:
            if self.max_user_applications == 1:
                desc = _("Limited to 1 use per basket")
            else:
                desc = _("Limited to %(total)d uses per basket") \
                    % {'total': self.max_basket_applications}
            restrictions.append({
                'description': desc,
                'is_satisfied': True})

        def hide_time_if_zero(dt):
            # Only show hours/minutes if they have been specified
            if dt.tzinfo:
                localtime = dt.astimezone(get_current_timezone())
            else:
                localtime = dt
            if localtime.hour == 0 and localtime.minute == 0:
                return date_filter(localtime, settings.DATE_FORMAT)
            return date_filter(localtime, settings.DATETIME_FORMAT)

        if self.start_datetime or self.end_datetime:
            today = now()
            if self.start_datetime and self.end_datetime:
                desc = _("Available between %(start)s and %(end)s") \
                    % {'start': hide_time_if_zero(self.start_datetime),
                       'end': hide_time_if_zero(self.end_datetime)}
                is_satisfied \
                    = self.start_datetime <= today <= self.end_datetime
            elif self.start_datetime:
                desc = _("Available from %(start)s") % {
                    'start': hide_time_if_zero(self.start_datetime)}
                is_satisfied = today >= self.start_datetime
            elif self.end_datetime:
                desc = _("Available until %(end)s") % {
                    'end': hide_time_if_zero(self.end_datetime)}
                is_satisfied = today <= self.end_datetime
            restrictions.append({
                'description': desc,
                'is_satisfied': is_satisfied})

        if self.max_discount:
            desc = _("Limited to a cost of %(max)s") % {
                'max': currency(self.max_discount)}
            restrictions.append({
                'description': desc,
                'is_satisfied': self.total_discount < self.max_discount})

        return restrictions
示例#8
0
 def get_upsell_message(self, offer, basket):
     value_of_matches = self._get_value_of_matches(offer, basket)
     return _('Spend %(value)s more from %(range)s') % {
         'value': currency(self.value - value_of_matches),
         'range': self.range
     }
示例#9
0
 def description(self):
     return self._description % {
         'amount': currency(self.value),
         'range': range_anchor(self.range)
     }
示例#10
0
 def name(self):
     return self._description % {
         'amount': currency(self.value),
         'range': str(self.range).lower()
     }
示例#11
0
 def name(self):
     return self._description % {'amount': currency(self.value)}
示例#12
0
 def name(self):
     return self._description % {
         'value': currency(self.value),
         'range': self.range.name.lower()
     }