Revised documentation and type hints of the template filters to format the numbers.
This commit is contained in:
parent
eb162c95df
commit
2db018f18b
@ -20,7 +20,7 @@
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Union, Optional
|
from typing import Optional
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
@ -32,14 +32,14 @@ from mia_core.period import Period
|
|||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
def _format_positive_amount(value: Union[str, Decimal]) -> str:
|
def _format_positive_amount(value: Decimal) -> str:
|
||||||
"""Formats a positive amount, groups every 3 digits by commas.
|
"""Formats a positive amount, groups every 3 digits by commas.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
value: The amount.
|
value: The amount.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ReportUrl: The formatted amount.
|
str: The amount in the desired format.
|
||||||
"""
|
"""
|
||||||
s = str(value)
|
s = str(value)
|
||||||
while True:
|
while True:
|
||||||
@ -53,7 +53,7 @@ def _format_positive_amount(value: Union[str, Decimal]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def accounting_amount(value: Union[Decimal]) -> str:
|
def accounting_amount(value: Optional[Decimal]) -> str:
|
||||||
"""Formats an amount with the accounting notation, grouping every 3 digits
|
"""Formats an amount with the accounting notation, grouping every 3 digits
|
||||||
by commas, and marking negative numbers with brackets instead of signs.
|
by commas, and marking negative numbers with brackets instead of signs.
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ def accounting_amount(value: Union[Decimal]) -> str:
|
|||||||
value: The amount.
|
value: The amount.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ReportUrl: The formatted amount.
|
str: The amount in the desired format.
|
||||||
"""
|
"""
|
||||||
if value is None:
|
if value is None:
|
||||||
return ""
|
return ""
|
||||||
@ -74,14 +74,14 @@ def accounting_amount(value: Union[Decimal]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def short_amount(value: Union[Decimal]) -> str:
|
def short_amount(value: Optional[Decimal]) -> str:
|
||||||
"""Formats an amount, groups every 3 digits by commas.
|
"""Formats an amount, groups every 3 digits by commas.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
value: The amount.
|
value: The amount.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ReportUrl: The formatted amount.
|
str: The amount in the desired format.
|
||||||
"""
|
"""
|
||||||
if value is None:
|
if value is None:
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user