Skip to content

Commit

Permalink
[FIX] l10n_es_aeat: Admit only valid character set on formatString
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza authored and ozono committed Oct 25, 2020
1 parent f51a79f commit 34409b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions l10n_es_aeat/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import test_l10n_es_aeat
17 changes: 17 additions & 0 deletions l10n_es_aeat/tests/test_l10n_es_aeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Pedro M. Baeza <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests import common


class TestL10nEsAeat(common.TransactionCase):
def setUp(self):
super(TestL10nEsAeat, self).setUp()
self.export_model = self.env["l10n.es.aeat.report.export_to_boe"]

def test_format_string(self):
text = u" &'(),-./01:;abAB_ÇÑ\"áéíóúÁÉÍÓÚ+!"
self.assertEqual(
self.export_model._formatString(text, len(text)),
u" &'(),-./01:;ABAB_ÇÑ\"AEIOUAEIOU ".encode('iso-8859-1'))
9 changes: 6 additions & 3 deletions l10n_es_aeat/wizard/export_to_boe.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ def _formatString(self, text, length, fill=' ', align='<'):
en mayúsculas sin caracteres especiales, y sin vocales acentuadas.
Para los caracteres específicos del idioma se utilizará la
codificación ISO-8859-1. De esta forma la letra “Ñ” tendrá el
valor ASCII 209 (Hex. D1) y la “Ç”(cedilla mayúscula) el valor
valor ASCII 209 (Hex. D1) y la “Ç” (cedilla mayúscula) el valor
ASCII 199 (Hex. C7).'
"""
if not text:
return fill * length
# Replace accents and convert to upper
from unidecode import unidecode
text = unidecode(unicode(text))
text = text.upper()
text = unicode(text.upper())
text = ''.join([unidecode(x) if x not in (u'Ñ', u'Ç') else x
for x in text])
text = re.sub(
ur"[^A-Z0-9\s\.,-_&'´\\:;/\(\)ÑÇ\"]", '', text, re.UNICODE | re.X)
ascii_string = text.encode('iso-8859-1')
# Cut the string if it is too long
if len(ascii_string) > length:
Expand Down

0 comments on commit 34409b5

Please sign in to comment.