Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
pass through the currency from the region (bug 858806)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed Apr 15, 2013
1 parent 42dc23d commit 2a69928
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions apps/market/models.py
Expand Up @@ -218,8 +218,13 @@ def has_price(self):
def get_price(self):
return self.price.get_price()

def get_price_locale(self):
return self.price.get_price_locale()
def get_price_locale(self, currency=None):
"""
Retuns a price for this locale. If you already know the currency
you would like, we will us that. Otherwise we will look it up
based on locale.
"""
return self.price.get_price_locale(currency=currency)

def is_complete(self):
return bool(self.addon and self.price and
Expand Down
4 changes: 4 additions & 0 deletions apps/market/tests/test_models.py
Expand Up @@ -68,6 +68,10 @@ def test_has_valid_permissions_token_ignore(self):
ap.paypal_permissions_token = 'asd'
assert ap.has_valid_permissions_token()

def test_price_locale(self):
ap = AddonPremium(addon=self.addon, price=self.tier_one)
eq_(ap.get_price_locale('CAD'), 'CA$3.01')


class TestPrice(amo.tests.TestCase):
fixtures = ['market/prices.json']
Expand Down
5 changes: 3 additions & 2 deletions mkt/site/helpers.py
Expand Up @@ -95,7 +95,7 @@ def market_button(context, product, receipt_type=None, classes=None):
if installed or purchased:
label = _('Install')
else:
label = product.get_price()
label = product.get_price(request.REGION.default_currency)

# Free apps and purchased apps get active install buttons.
if not product.is_premium() or purchased:
Expand Down Expand Up @@ -151,7 +151,8 @@ def product_as_dict(request, product, purchased=None, receipt_type=None,
if product.has_price():
ret.update({
'price': product.premium.get_price() or '0',
'priceLocale': product.premium.get_price_locale(),
'priceLocale': product.premium.get_price_locale(
request.REGION.default_currency),
})
currencies = product.premium.supported_currencies()
if len(currencies) > 1 and waffle.switch_is_active('currencies'):
Expand Down
2 changes: 1 addition & 1 deletion mkt/site/templates/site/tiles/app.html
Expand Up @@ -27,7 +27,7 @@ <h3>{{ product.name }}</h3>
{% if product.listed_authors -%}
<div class="author lineclamp vital">{{ product.listed_authors[0].name }}</div>
{%- endif %}
<div class="price vital">{{ product.get_price() }}</div>
<div class="price vital">{{ product.get_price(request.REGION.default_currency) }}</div>
<div class="rating vital{{ ' unrated' if not product.total_reviews }}">
{%- if tag != "a" -%}
<a href="{{ product.get_ratings_url() }}" class="rating_link">
Expand Down
5 changes: 5 additions & 0 deletions mkt/site/tests/test_helpers.py
Expand Up @@ -16,6 +16,7 @@
from market.models import AddonPremium, AddonPurchase
from users.models import UserProfile

from mkt.constants import regions
from mkt.site.helpers import (css, get_login_link, js, market_button,
market_tile)
from mkt.webapps.models import Webapp
Expand All @@ -38,6 +39,7 @@ def setUp(self):
request.TABLET = False
request.META = {'HTTP_USER_AGENT': 'Mozilla/5.0 (Mobile; rv:17.0) '
'Gecko/17.0 Firefox/17.0'}
request.REGION = regions.US()
self.context = {'request': request}

def test_not_webapp(self):
Expand Down Expand Up @@ -92,6 +94,9 @@ def test_is_premium_webapp_gaia(self):

def test_is_premium_webapp_foreign(self):
self.make_premium(self.webapp)
self.context['request'].REGION = regions.SPAIN
# The region is set to Spain, so the currency is set EUR
# and the display is set to French.
with self.activate('fr'):
doc = pq(market_tile(self.context, self.webapp))
data = json.loads(doc('.mkt-tile').attr('data-product'))
Expand Down
4 changes: 2 additions & 2 deletions mkt/webapps/models.py
Expand Up @@ -484,9 +484,9 @@ def has_price(self):
return bool(self.is_premium() and self.premium and
self.premium.has_price())

def get_price(self):
def get_price(self, currency):
if self.has_price():
return self.premium.get_price_locale()
return self.premium.get_price_locale(currency)
return _(u'Free')

@amo.cached_property
Expand Down

0 comments on commit 2a69928

Please sign in to comment.