diff --git a/.docker_files/requirements.txt b/.docker_files/requirements.txt index b3a00f9..82c5734 100644 --- a/.docker_files/requirements.txt +++ b/.docker_files/requirements.txt @@ -1,4 +1,5 @@ git+https://github.com/numigi/aeroolib@master +git+https://github.com/aeroo/currency2text@master babel==2.5.3 Genshi==0.7.5 freezegun==0.3.10 diff --git a/report_aeroo/__manifest__.py b/report_aeroo/__manifest__.py index 3358af9..9d9f14a 100644 --- a/report_aeroo/__manifest__.py +++ b/report_aeroo/__manifest__.py @@ -13,7 +13,7 @@ 'website': 'https://bit.ly/numigi-com', 'depends': ['mail'], 'external_dependencies': { - 'python': ['aeroolib', 'babel', 'genshi'], + 'python': ['aeroolib', 'babel', 'currency2text', 'genshi'], }, 'data': [ "security/security.xml", diff --git a/report_aeroo/extra_functions.py b/report_aeroo/extra_functions.py index 5bccf79..1e4d769 100755 --- a/report_aeroo/extra_functions.py +++ b/report_aeroo/extra_functions.py @@ -10,6 +10,7 @@ import logging import time from babel.core import localedata +from currency2text import supported_language from datetime import datetime, date, timedelta from html2text import html2text from io import BytesIO @@ -72,6 +73,23 @@ def decorator(func): return decorator +@aeroo_util("currency_to_text") +def currency_to_text(report, sum, currency = None, language = None): + lang = report._context.get("lang") or "en_US" + s_lang = supported_language.get(language or lang) + context = report._context + currency = currency or context.get("currency") + if currency is None: + raise ValidationError( + _( + "The function `currency_to_text` can not be evaluated without a currency. " + "You must either define a currency in the field `Currency Evaluation` of the " + "Aeroo report or call the function with a currency explicitely." + ) + ) + return str(s_lang.currency_to_text(sum, currency), "UTF-8") + + @aeroo_util("format_hours") def format_hours(report, value): hours = str(int(abs(value) // 1))