Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds BYN in rubles function #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pytils/numeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _get_plural_legacy(amount, extra_variants):
return get_plural(amount, variants, absence)


def rubles(amount, zero_for_kopeck=False):
def rubles(amount, zero_for_kopeck=False, by_rubles=False):
"""
Get string for money

Expand All @@ -227,7 +227,10 @@ def rubles(amount, zero_for_kopeck=False):

pts = []
amount = round(amount, 2)
pts.append(sum_string(int(amount), 1, (u"рубль", u"рубля", u"рублей")))
if not by_rubles:
pts.append(sum_string(int(amount), 1, (u"рубль", u"рубля", u"рублей")))
else:
pts.append(sum_string(int(amount), 1, (u"белорусский рубль", u"белорусских рубля", u"белорусских рублей")))
remainder = _get_float_remainder(amount, 2)
iremainder = int(remainder)

Expand Down
27 changes: 27 additions & 0 deletions pytils/test/test_numeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ def testRubles(self):
u"три рубля ноль копеек")
self.assertEquals(pytils.numeral.rubles(long(3)),
u"три рубля")
#BYN - belarussian rubels
self.assertEquals(pytils.numeral.rubles(10.01, False, True),
u"десять белорусских рублей одна копейка")
self.assertEquals(pytils.numeral.rubles(10.10, False, True),
u"десять белорусских рублей десять копеек")
self.assertEquals(pytils.numeral.rubles(2.353, False, True),
u"два белорусских рубля тридцать пять копеек")
self.assertEquals(pytils.numeral.rubles(2.998, False, True),
u"три белорусских рубля")
self.assertEquals(pytils.numeral.rubles(3, False, True),
u"три белорусских рубля")
self.assertEquals(pytils.numeral.rubles(3, True, True),
u"три белорусских рубля ноль копеек")
self.assertEquals(pytils.numeral.rubles(long(3), False, True),
u"три белорусских рубля")


def testRublesDecimal(self):
"""
Expand All @@ -203,6 +219,17 @@ def testRublesDecimal(self):
u"три рубля")
self.assertEquals(pytils.numeral.rubles(D(3), True),
u"три рубля ноль копеек")
# BYN - belarussian rubels
self.assertEquals(pytils.numeral.rubles(D("10.01"), False, True),
u"десять белорусских рублей одна копейка")
self.assertEquals(pytils.numeral.rubles(D("10.10"), False, True),
u"десять белорусских рублей десять копеек")
self.assertEquals(pytils.numeral.rubles(D("2.35"), False, True),
u"два белорусских рубля тридцать пять копеек")
self.assertEquals(pytils.numeral.rubles(D(3), False, True),
u"три белорусских рубля")
self.assertEquals(pytils.numeral.rubles(D(3), True, True),
u"три белорусских рубля ноль копеек")

def testRublesExceptions(self):
"""
Expand Down