changeset 35d95390548f in modules/currency:default
details: https://hg.tryton.org/modules/currency?cmd=changeset;node=35d95390548f
description:
Remove forbidden chars from imported names
issue9829
review318821002
diffstat:
scripts/import_currencies.py | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diffs (37 lines):
diff -r a37f8f8d8014 -r 35d95390548f scripts/import_currencies.py
--- a/scripts/import_currencies.py Sat Dec 19 17:08:45 2020 +0100
+++ b/scripts/import_currencies.py Tue Jan 19 22:42:52 2021 +0100
@@ -37,6 +37,14 @@
yield l.code
+def _remove_forbidden_chars(name):
+ from trytond.model.fields import Char
+ for c in Char.forbidden_chars:
+ if c in name:
+ name.replace(c, ' ')
+ return name.strip()
+
+
def get_currencies():
Currency = Model.get('currency.currency')
return {c.code: c for c in Currency.find([])}
@@ -54,7 +62,7 @@
record = currencies[code]
else:
record = Currency(code=code)
- record.name = currency.name
+ record.name = _remove_forbidden_chars(currency.name)
record.numeric_code = currency.numeric
record.symbol = codes.get_symbol(currency.alpha_3) or currency.alpha_3
records.append(record)
@@ -78,7 +86,8 @@
records = []
for currency in _progress(pycountry.currencies):
record = Currency(currencies[currency.alpha_3].id)
- record.name = gnutranslation.gettext(currency.name)
+ record.name = _remove_forbidden_chars(
+ gnutranslation.gettext(currency.name))
records.append(record)
Currency.save(records)