Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 def test_format_price(self):
     price = Product.format_price(99)
     self.assertEqual(price, "99 kr")