satdigitalinvoice.formatting_functions.common   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 26
dl 0
loc 45
rs 10
c 0
b 0
f 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A fecha_mes() 0 2 1
A fecha() 0 2 1
A num_letras() 0 2 1
A pesos() 0 5 1
A get_month_name() 0 2 1
A numero() 0 2 1
A porcentaje() 0 2 1
A delta_tiempo() 0 5 2
1
from babel.dates import format_date, get_month_names
2
from num2words import num2words
3
4
LANG = 'es_CO'
5
LOCALE = 'es_MX'
6
7
8
def pesos(amount):
9
    decimal_part = "{:.2f}".format(amount).split(".")[1]
10
    integer_part = num2words(int(amount), lang=LANG, to='currency').upper()
11
12
    return "${0:,.2f} (SON: {1} {2}/100M.N.)".format(amount, integer_part, decimal_part)
13
14
15
def num_letras(number):
16
    return num2words(number, lang=LANG).upper()
17
18
19
def numero(k):
20
    return str(k) + ' (' + num_letras(k) + ')'
21
22
23
def porcentaje(k):
24
    return str(k) + '% (' + num_letras(k) + ' POR CIENTO)'
25
26
27
def fecha(date):
28
    return format_date(date, locale=LOCALE, format="d 'de' MMMM 'del' y").upper()
29
30
31
def fecha_mes(date):
32
    return format_date(date, locale=LOCALE, format="'Mes de' MMMM 'del' y").upper()
33
34
35
# function to get month name from number
36
def get_month_name(month_number):
37
    return get_month_names('wide', locale=LOCALE)[month_number].upper()
38
39
40
def delta_tiempo(duracion):
41
    months = duracion.years * 12 + duracion.months
42
    if months == 12:
43
        return 'UN AÑO'
44
    return num_letras(duracion.months) + ' MESES'
45