Exemplo n.º 1
0
    def __unicode__(self):
        if self.__use_l10n():
            locale = self.__get_current_locale()
            if locale:
                return format_money(self, locale=locale)

        return format_money(self)
Exemplo n.º 2
0
    def __unicode__(self):
        if self.__use_l10n():
            locale = self.__get_current_locale()
            if locale:
                return format_money(self, locale=locale)

        return format_money(self)
Exemplo n.º 3
0
 def __str__(self):
     from moneyed.localization import format_money
     if PYTHON2:
         return '%s%s' % (self.currency.code,
                          format_money(self, include_symbol=False))
     else:
         return format_money(self)
Exemplo n.º 4
0
    def test_format_money_uses_default_formatting_definition_if_given_locale_not_registered(
            self):
        m1 = Money(Decimal('100'), 'GBP')

        # should format with 'default' formatting definition
        expected_default_formatting = format_money(m1)

        # should format with 'default' formatting definition since
        # 'en_AU' is not a registered formatting definition
        returned_formatting = format_money(m1, locale='en_AU')
        assert returned_formatting == expected_default_formatting
Exemplo n.º 5
0
 def __str__(self):
     from moneyed.localization import format_money
     first = True
     us = u""
     for mon in self.getMoneys():
         if first:
             us = u"" + format_money(mon)
             first = False
         else:
             us = us + u", " + format_money(mon)
     return us
Exemplo n.º 6
0
 def test_format_money(self):
     # Two decimal places by default
     assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
     # No decimal point without fractional part
     assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
     # locale == pl_PL
     one_million_pln = Money('1000000', 'PLN')
     # Two decimal places by default
     assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'
     assert format_money(self.one_million_bucks, locale='pl_PL') == '1 000 000,00 USD'
     # No decimal point without fractional part
     assert format_money(one_million_pln, locale='pl_PL',
                         decimal_places=0) == '1 000 000 zł'
Exemplo n.º 7
0
 def test_format_money(self):
     # Two decimal places by default
     assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
     # No decimal point without fractional part
     assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
     # locale == pl_PL
     one_million_pln = Money('1000000', 'PLN')
     # Two decimal places by default
     assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'
     assert format_money(self.one_million_bucks, locale='pl_PL') == '1 000 000,00 USD'
     # No decimal point without fractional part
     assert format_money(one_million_pln, locale='pl_PL',
                         decimal_places=0) == '1 000 000 zł'
Exemplo n.º 8
0
 def default(self, o):
     if isinstance(o, Money):
         return format_money(o, locale=translation.get_language())
     if isinstance(o, Decimal):
         return str(m.floor(o))
     # Let the base class default method raise the TypeError
     return json.JSONEncoder.default(self, o)
Exemplo n.º 9
0
def format_money(m: Money, latex: bool = False) -> str:
    from moneyed import localization

    ret: str = localization.format_money(m, locale="en_US")
    if latex and "$" in ret:
        ret = ret.replace("$", r"\$")
    return ret
Exemplo n.º 10
0
def format_money_remove_aud(self, **kwargs):
    """
    Monkey patch money.Money.format so that the default currency (AUD) isn't displayed
    when calling Money.format()

    @author: Alex Hayes <*****@*****.**>
    """
    return format_money(self, **kwargs).replace('A$', '$')
Exemplo n.º 11
0
    def __unicode__(self):
        kwargs = {'money': self, 'decimal_places': DECIMAL_PLACES}
        if self.is_localized:
            locale = get_current_locale()
            if locale:
                kwargs['locale'] = locale

        return format_money(**kwargs)
Exemplo n.º 12
0
def format_money_remove_aud(self, **kwargs):
    """
    Monkey patch money.Money.format so that the default currency (AUD) isn't displayed
    when calling Money.format()

    @author: Alex Hayes <*****@*****.**>
    """
    return format_money(self, **kwargs).replace('A$', '$')
Exemplo n.º 13
0
    def __str__(self):
        kwargs = {"money": self, "decimal_places": self.decimal_places}
        if self.is_localized:
            locale = get_current_locale()
            if locale:
                kwargs["locale"] = locale

        return format_money(**kwargs)
Exemplo n.º 14
0
    def __unicode__(self):
        kwargs = {'money': self, 'decimal_places': DECIMAL_PLACES}
        if self.is_localized:
            locale = get_current_locale()
            if locale:
                kwargs['locale'] = locale

        return format_money(**kwargs)
Exemplo n.º 15
0
def moneyformat(value, currency = 'PLN', decimal_pos = 2, locale = None):
    locale = get_money_locale(locale)

    if isinstance(value, Money):
        pass
    else:
        value = Money(value, currency = get_currency(str(currency)))

    return format_money(value, decimal_places = decimal_pos, locale = locale)
    def format_money(self, money):
        """Returns locale formated money

        :param money: Money
        :type money: moneyed.Money

        :rtype: unicode
        """
        return format_money(money, locale=self.locale())
Exemplo n.º 17
0
def convtomoney(arr):
    """ Converts array of floats/integers into an array of formatted money objects. """
    floatarr = np.array(arr)
    flat = floatarr.flatten()
    nelem = len(flat)
    dim = floatarr.shape
    monarr = np.zeros(nelem, dtype = object)
    for i in range(nelem):
        monarr[i] = format_money(Money(amount = str(flat[i]), currency = 'USD'), locale = 'en_US')
    return monarr.reshape(dim)
Exemplo n.º 18
0
 def test_format_money_fr(self):
     # locale == fr_FR
     one_million_eur = Money('1000000', 'EUR')
     one_million_cad = Money('1000000', 'CAD')
     assert format_money(one_million_eur, locale='fr_FR') == '1 000 000,00 €'
     assert format_money(self.one_million_bucks, locale='fr_FR') == '1 000 000,00 $ US'
     assert format_money(one_million_cad, locale='fr_FR') == '1 000 000,00 $ CA'
     # No decimal point without fractional part
     assert format_money(one_million_eur, locale='fr_FR',
                         decimal_places=0) == '1 000 000 €'
     # locale == fr_CA
     assert format_money(one_million_cad, locale='fr_CA') == '1 000 000,00 $'
     assert format_money(self.one_million_bucks, locale='fr_CA') == '1 000 000,00 $ US'
     assert format_money(one_million_eur, locale='fr_CA') == '1 000 000,00 €'
Exemplo n.º 19
0
 def test_format_money_fr(self):
     # locale == fr_FR
     one_million_eur = Money('1000000', 'EUR')
     one_million_cad = Money('1000000', 'CAD')
     assert format_money(one_million_eur, locale='fr_FR') == '1 000 000,00 €'
     assert format_money(self.one_million_bucks, locale='fr_FR') == '1 000 000,00 $ US'
     assert format_money(one_million_cad, locale='fr_FR') == '1 000 000,00 $ CA'
     # No decimal point without fractional part
     assert format_money(one_million_eur, locale='fr_FR',
                         decimal_places=0) == '1 000 000 €'
     # locale == fr_CA
     assert format_money(one_million_cad, locale='fr_CA') == '1 000 000,00 $'
     assert format_money(self.one_million_bucks, locale='fr_CA') == '1 000 000,00 $ US'
     assert format_money(one_million_eur, locale='fr_CA') == '1 000 000,00 €'
Exemplo n.º 20
0
 def test_format_money(self):
     # Two decimal places by default
     assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
     # No decimal point without fractional part
     assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
     # Locale format not included, should fallback to DEFAULT
     assert format_money(self.one_million_bucks, locale='es_ES') == 'US$1,000,000.00'
     # locale == pl_PL
     one_million_pln = Money('1000000', 'PLN')
     # Two decimal places by default
     assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'
     assert format_money(self.one_million_bucks, locale='pl_PL') == '1 000 000,00 USD'
     # No decimal point without fractional part
     assert format_money(one_million_pln, locale='pl_PL',
                         decimal_places=0) == '1 000 000 zł'
Exemplo n.º 21
0
 def test_format_money(self):
     # Two decimal places by default
     assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
     # No decimal point without fractional part
     assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
     # Locale format not included, should fallback to DEFAULT
     assert format_money(self.one_million_bucks, locale='es_ES') == 'US$1,000,000.00'
     # locale == pl_PL
     one_million_pln = Money('1000000', 'PLN')
     # Two decimal places by default
     assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'
     assert format_money(self.one_million_bucks, locale='pl_PL') == 'US$1 000 000,00'
     # No decimal point without fractional part
     assert format_money(one_million_pln, locale='pl_PL',
                         decimal_places=0) == '1 000 000 zł'
Exemplo n.º 22
0
def currency(value):
    return format_money(value, locale=DJANGO)
Exemplo n.º 23
0
 def fmt(money):
     return format_money(money, locale=to_locale(get_language() or 'en-us'))
Exemplo n.º 24
0
    def test_format_money(self):
        # Two decimal places by default
        assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
        # No decimal point without fractional part
        assert format_money(self.one_million_bucks,
                            decimal_places=0) == 'US$1,000,000'
        # locale == pl_PL
        one_million_pln = Money('1000000', 'PLN')
        # Two decimal places by default
        assert format_money(one_million_pln,
                            locale='pl_PL') == '1 000 000,00 zł'

        # overriden sign/format locale display default sign with locale group parameter
        assert format_money(self.one_million_bucks,
                            locale='pl_PL') == 'US$1 000 000,00'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_bucks,
                            locale='fr_FR') == 'US$1,000,000.00'

        # No decimal point without fractional part
        assert format_money(one_million_pln, locale='pl_PL',
                            decimal_places=0) == '1 000 000 zł'

        # add different sign for money USD in locale pl_PL
        _sign('pl_PL', moneyed.USD, prefix='$')
        assert format_money(self.one_million_bucks,
                            locale='pl_PL') == '$1 000 000,00'

        # default locale display correct money sign with default group parameter
        assert format_money(self.one_million_euros) == '1,000,000.00 €'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_euros,
                            locale='fr_FR') == '1,000,000.00 €'
        # overriden sign/locale locale display default money sign with locale group parameter
        assert format_money(self.one_million_euros,
                            locale='en_US') == '1,000,000.00 €'

        # add format for fr_FR locale
        _format("fr_FR",
                group_size=3,
                group_separator=" ",
                decimal_point=",",
                positive_sign="",
                trailing_positive_sign="",
                negative_sign="-",
                trailing_negative_sign="",
                rounding_method=ROUND_HALF_EVEN)
        # overriden format locale display correct sign with locale group parameter
        assert format_money(self.one_million_euros,
                            locale='fr_FR') == '1 000 000,00 €'
Exemplo n.º 25
0
def currency(value):
    return format_money(value, locale=DJANGO)
Exemplo n.º 26
0
 def formatted_captured_amount(self, obj):
     if obj.captured_amount is not None:
         return format_money(obj.captured_amount)
Exemplo n.º 27
0
 def __unicode__(self):
     from moneyed.localization import format_money
     return format_money(self)
    def test_format_money(self):
        # Two decimal places by default
        assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
        # No decimal point without fractional part
        assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
        # locale == pl_PL
        one_million_pln = Money('1000000', 'PLN')
        # Two decimal places by default
        assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'

        # overriden sign/format locale display default sign with locale group parameter
        assert format_money(self.one_million_bucks, locale='pl_PL') == 'US$1 000 000,00'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_bucks, locale='fr_FR') == 'US$1,000,000.00'

        # No decimal point without fractional part
        assert format_money(one_million_pln, locale='pl_PL', decimal_places=0) == '1 000 000 zł'

        # add different sign for money USD in locale pl_PL
        _sign('pl_PL', moneyed.USD, prefix='$')
        assert format_money(self.one_million_bucks, locale='pl_PL') == '$1 000 000,00'

        # default locale display correct money sign with default group parameter
        assert format_money(self.one_million_euros) == '1,000,000.00 €'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_euros, locale='fr_FR') == '1,000,000.00 €'
        # overriden sign/locale locale display default money sign with locale group parameter
        assert format_money(self.one_million_euros, locale='en_US') == '1,000,000.00 €'

        # add format for fr_FR locale
        _format("fr_FR", group_size=3, group_separator=" ", decimal_point=",",
                positive_sign="", trailing_positive_sign="",
                negative_sign="-", trailing_negative_sign="",
                rounding_method=ROUND_HALF_EVEN)
        # overriden format locale display correct sign with locale group parameter
        assert format_money(self.one_million_euros, locale='fr_FR') == '1 000 000,00 €'
Exemplo n.º 29
0
 def formatted_total(self, obj):
     return format_money(obj.total)
Exemplo n.º 30
0
 def test_format_money(self):
     # Two decimal places by default
     assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
     # No decimal point without fractional part
     assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
Exemplo n.º 31
0
 def test_format_money_by(self):
     assert format_money(Money('10', 'BYN'), locale='ru_RU') == '10,00 руб.'
     assert format_money(Money('10.15', 'BYN'),
                         locale='ru_RU') == '10,15 руб.'
     assert format_money(Money('1234.56', 'BYN'),
                         locale='ru_RU') == '1 234,56 руб.'
Exemplo n.º 32
0
 def unbreakable_amount(self, obj):
     """Correctly formatted amount with unbreakable spaces."""
     locale = to_locale(get_language())
     amount = format_money(obj.amount, locale=locale)
     return mark_safe(amount.replace(' ', '&nbsp;'))
Exemplo n.º 33
0
 def __str__(self):
     from moneyed.localization import format_money
     return format_money(self)
Exemplo n.º 34
0
 def test_format_money_ru(self):
     assert format_money(Money('10', 'RUB'), locale='ru_RU') == '10₽'
     assert format_money(Money('1234', 'RUB'), locale='ru_RU') == '1 234₽'
Exemplo n.º 35
0
 def money_str(amount):
     return format_money(Money(amount, 'GBP'), locale='en_GB')
Exemplo n.º 36
0
 def __str__(self):
     from moneyed.localization import format_money
     if PYTHON2:
         return '%s%s' % (self.currency.code, format_money(self, include_symbol=False))
     else:
         return format_money(self)
Exemplo n.º 37
0
def amount(obj):
    return format_money(obj.amount)