def get_fixed_discount_for(self, amount):
if self.discount_value_type == self.DISCOUNT_VALUE_FIXED:
discount_price = Price(net=self.discount_value,
currency=settings.DEFAULT_CURRENCY)
discount = FixedDiscount(
amount=discount_price, name=smart_text(self))
elif self.discount_value_type == self.DISCOUNT_VALUE_PERCENTAGE:
discount = percentage_discount(
value=self.discount_value, name=smart_text(self))
fixed_discount_value = amount - discount.apply(amount)
discount = FixedDiscount(
amount=fixed_discount_value, name=smart_text(self))
else:
raise NotImplementedError('Unknown discount value type')
if discount.amount > amount:
return FixedDiscount(amount, name=smart_text(self))
else:
return discount
评论列表
文章目录