Skip to content

Commit

Permalink
fix rounding of standard tips and donation limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed May 19, 2019
1 parent 5568e06 commit eaf61e9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions liberapay/constants.py
Expand Up @@ -104,11 +104,19 @@ def __missing__(self, currency):


class _DonationLimits(defaultdict): class _DonationLimits(defaultdict):
def __missing__(self, currency): def __missing__(self, currency):
minimum = Money.MINIMUMS[currency].amount
eur_weekly_amounts = DONATION_LIMITS_EUR_USD['weekly']
converted_weekly_amounts = (
convert_symbolic_amount(eur_weekly_amounts[0], currency),
convert_symbolic_amount(eur_weekly_amounts[1], currency)
)
r = { r = {
period: ( 'weekly': tuple(Money(x, currency) for x in converted_weekly_amounts),
Money(convert_symbolic_amount(eur_amounts[0], currency, rounding=ROUND_UP), currency), 'monthly': tuple(
Money(convert_symbolic_amount(eur_amounts[1], currency, rounding=ROUND_UP), currency) Money((x * Decimal(52) / Decimal(12)).quantize(minimum, rounding=ROUND_UP), currency)
) for period, eur_amounts in DONATION_LIMITS_EUR_USD.items() for x in converted_weekly_amounts
),
'yearly': tuple(Money(x * Decimal(52), currency) for x in converted_weekly_amounts),
} }
self[currency] = r self[currency] = r
return r return r
Expand All @@ -118,8 +126,7 @@ def __missing__(self, currency):
'weekly': DONATION_LIMITS_WEEKLY_EUR_USD, 'weekly': DONATION_LIMITS_WEEKLY_EUR_USD,
'monthly': tuple((x * Decimal(52) / Decimal(12)).quantize(D_CENT, rounding=ROUND_UP) 'monthly': tuple((x * Decimal(52) / Decimal(12)).quantize(D_CENT, rounding=ROUND_UP)
for x in DONATION_LIMITS_WEEKLY_EUR_USD), for x in DONATION_LIMITS_WEEKLY_EUR_USD),
'yearly': tuple((x * Decimal(52)).quantize(D_CENT) 'yearly': tuple(x * Decimal(52) for x in DONATION_LIMITS_WEEKLY_EUR_USD),
for x in DONATION_LIMITS_WEEKLY_EUR_USD),
} }
DONATION_LIMITS = _DonationLimits(None, { DONATION_LIMITS = _DonationLimits(None, {
'EUR': {k: (Money(v[0], 'EUR'), Money(v[1], 'EUR')) for k, v in DONATION_LIMITS_EUR_USD.items()}, 'EUR': {k: (Money(v[0], 'EUR'), Money(v[1], 'EUR')) for k, v in DONATION_LIMITS_EUR_USD.items()},
Expand Down Expand Up @@ -426,7 +433,7 @@ class _StandardTips(defaultdict):
def __missing__(self, currency): def __missing__(self, currency):
r = [ r = [
make_standard_tip( make_standard_tip(
label, convert_symbolic_amount(weekly, currency, rounding=ROUND_UP), currency label, convert_symbolic_amount(weekly, currency), currency
) for label, weekly in STANDARD_TIPS_EUR_USD ) for label, weekly in STANDARD_TIPS_EUR_USD
] ]
self[currency] = r self[currency] = r
Expand Down

0 comments on commit eaf61e9

Please sign in to comment.