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

Add currency2text support #59

Open
wants to merge 7 commits into
base: 14.0
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
1 change: 1 addition & 0 deletions .docker_files/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion report_aeroo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions report_aeroo/extra_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +73,23 @@
return decorator


@aeroo_util("currency_to_text")
def currency_to_text(report, sum, currency = None, language = None):

Check warning on line 77 in report_aeroo/extra_functions.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

report_aeroo/extra_functions.py#L77

Redefining built-in 'sum'
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")

Check notice on line 91 in report_aeroo/extra_functions.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

report_aeroo/extra_functions.py#L91

Trailing whitespace

@aeroo_util("format_hours")
def format_hours(report, value):
hours = str(int(abs(value) // 1))
Expand Down