def get_currencies(self):
        """
        Calculates prices for all currencies and returns them in a dict.
        """
        currencies = {}

        for currency in Currency.objects.filter(is_active=True):
            price = calculate_price(self.get_price(), currency.code)
            unit_price = calculate_price(self.get_unit_price(), currency.code)

            currencies[currency.code] = dict(
                code=force_str(currency.code),
                name=force_str(currency.name),
                symbol=force_str(currency.symbol),
                factor=force_str(currency.factor),
                is_base=currency.is_base,
                is_default=currency.is_default,
                price=force_str(price),
                unit_price=force_str(unit_price),
            )

        return dict(**currencies)
Beispiel #2
0
 def test_calculate_price_fail(self):
     res = calculate_price('10', 'GBP')
     self.assertEqual(res, Decimal('0.00'))
Beispiel #3
0
 def test_calculate_price_success(self):
     res = calculate_price('10', 'USD')
     self.assertEqual(res, Decimal('15.00'))
	def render(self, context):
		try:
			return calculate_price(self.price.resolve(context),
				self.currency.resolve(context))
		except template.VariableDoesNotExist:
			return ''
def set_currency(value, arg):
	return calculate_price(value, arg)
Beispiel #6
0
 def test_calculate_price_fail(self):
     res = calculate_price('10', 'GBP')
     self.assertEqual(res, Decimal('0.00'))
Beispiel #7
0
 def test_calculate_price_success(self):
     res = calculate_price('10', 'USD')
     self.assertEqual(res, Decimal('15.00'))
Beispiel #8
0
 def render(self, context):
     try:
         return calculate_price(self.price.resolve(context),
                                self.currency.resolve(context))
     except template.VariableDoesNotExist:
         return ''
Beispiel #9
0
def set_currency(value, arg):
    return calculate_price(value, arg)