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 = u"'%(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
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
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}
def description(self): return self._description % { 'amount': currency(self.value), 'range': range_anchor(self.range)}
def name(self): return self._description % { 'amount': currency(self.value), 'range': six.text_type(self.range).lower()}
def name(self): return self._description % {'amount': currency(self.value)}
def name(self): return self._description % { 'value': currency(self.value), 'range': self.range.name.lower() }
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