From e758db31ad55fd6b6a295b1ce7b2a58edf682a31 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 27 Dec 2017 10:45:18 -0500 Subject: [PATCH] hooks.add_entity: Don't try to rearrange non-Latin names. --- import2ledger/hooks/add_entity.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/import2ledger/hooks/add_entity.py b/import2ledger/hooks/add_entity.py index d4f6191..a4d6a85 100644 --- a/import2ledger/hooks/add_entity.py +++ b/import2ledger/hooks/add_entity.py @@ -41,20 +41,24 @@ class AddEntityHook: if word: yield word - def _str2entity(self, s, trim_re): + def _str2entity(self, s, trim_re, name_shifts): parts = list(self._entity_parts(s, trim_re)) if not parts: return '' - parts.insert(0, parts.pop()) + for _ in range(name_shifts): + parts.insert(0, parts.pop()) if parts[-1].lower() in self.NAME_PREFIXES: parts.insert(0, parts.pop()) return '-'.join(parts) + def _name2entity(self, name, name_shifts): + name = self._remove_parens(name) + name = self._destroke(name) + entity = self._str2entity(name, self.NONASCII_RE, name_shifts) + if not entity: + entity = self._str2entity(name, self.NONALNUM_RE, 0) + return entity + def run(self, data): if ('payee' in data) and ('entity' not in data): - payee = self._remove_parens(data['payee']) - payee = self._destroke(payee) - entity = self._str2entity(payee, self.NONASCII_RE) - if not entity: - entity = self._str2entity(payee, self.NONALNUM_RE) - data['entity'] = entity + data['entity'] = self._name2entity(data['payee'], 1)