def format_price(context, price, args=False): if 'request' in context: request = context['request'] else: request = None if args == "decimals": formatted_price = Product.format_price(price, decimals=True, request=request) else: formatted_price = Product.format_price(price, request=request) return formatted_price
def get_shipping(self, formatted=False, decimals=False): total = 0 if self.carrier: total = self.carrier.get_total() if formatted: if decimals: total = Product.format_price(total, decimals=True) else: total = Product.format_price(total) return total
def get_to_pay(self, formatted=False, decimals=False): total = 0 total += self.get_total() total -= self.get_total_discount() total += self.get_shipping() if formatted: if decimals: total = Product.format_price(total, decimals=True) else: total = Product.format_price(total) return total
def get_total_vat(self, formatted=False, decimals=False): items = self.cartitem_set.all() total = 0 for item in items: total += item.product.get_vat() * item.amount if formatted: if decimals: total = Product.format_price(total, decimals=True) else: total = Product.format_price(total) return total
def get_total_discount(self, formatted=False, decimals=False): total = 0 price = self.get_total() if self.voucher is not None: if self.voucher.value_type == "percentage": total = price * self.voucher.value / 100 elif self.voucher.value_type == "value": if self.voucher.value > price: total = price else: total = self.voucher.value if formatted: if decimals: total = Product.format_price(total, decimals=True) else: total = Product.format_price(total) return total
def test_format_price(self): price = Product.format_price(99) self.assertEqual(price, "99 kr")