From 53c1bd0d583474661fbcc27944a84f97a8e37e45 Mon Sep 17 00:00:00 2001 From: Hong-Thai Nguyen Date: Fri, 10 Jul 2020 11:45:43 +0200 Subject: [PATCH] Fixing parsing new norme --- cfonb/parser/common.py | 21 ++++++++++++--------- cfonb/parser/statement.py | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cfonb/parser/common.py b/cfonb/parser/common.py index 37ee704..d06b837 100644 --- a/cfonb/parser/common.py +++ b/cfonb/parser/common.py @@ -97,8 +97,11 @@ def parse(self, line): if len(line) > self.size and len(line.strip()) <= self.size: line = line[:self.size] if len(line) != self.size: - raise ParsingError("Invalid line: >%s<. the len should be %s" - "instead of %s" % (line, self.size, len(line))) + if self._code == '05' and len(line) == 78: + line += ' ' * 42 + else: + raise ParsingError("Invalid line: >%s<. the len should be %s" + "instead of %s" % (line, self.size, len(line))) match = self.re.match(line) # re check if match is None: @@ -125,7 +128,7 @@ class ParserContent01(Parser): _regex = [ ('record_code', '(01)', 2), ('bank_code', G_N, 5), - ('_1', G__, 4), + ('_1', G_AN_, 4), ('desk_code', G_N, 5), ('currency_code', G_A_, 3), ('nb_of_dec', G_N_, 1), @@ -133,7 +136,7 @@ class ParserContent01(Parser): ('account_nb', G_AN, 11), ('_3', G__, 2), ('prev_date', G_N, 6), - ('_4', G__, 50), + ('_4', G_ALL, 50), ('prev_amount', G_AMT, 14), ('_5', G_ALL, 16), ] @@ -194,7 +197,7 @@ class ParserContent05(Parser): ('account_nb', G_AN, 11), ('operation_code', G_AN, 2), ('operation_date', G_N, 6), - ('_2', G__, 5), + ('_2', G_N_, 5), ('qualifier', G_AN, 3), ('additional_info', G_ALL, 70), ('_3', G__, 2), @@ -212,7 +215,7 @@ class ParserContent07(Parser): _regex = [ ('record_code', '(07)', 2), ('bank_code', G_N, 5), - ('_1', G__, 4), + ('_1', G_AN_, 4), ('desk_code', G_N, 5), ('currency_code', G_A_, 3), ('nb_of_dec', G_N_, 1), @@ -220,9 +223,9 @@ class ParserContent07(Parser): ('account_nb', G_AN, 11), ('_3', G__, 2), ('next_date', G_N, 6), - ('_4', G__, 50), + ('_4', G_ALL, 50), ('next_amount', G_AMT, 14), - ('_5', G__, 16), + ('_5', G_ALL, 16), ] def _post(self, res): @@ -354,7 +357,7 @@ def _post(self, res): res = super(ParserMMO, self)._post(res) res['equivalent_amount'] = float(res['equivalent_amount'])\ /float(res['nb_of_dec_amount']) - if res['exchange_rate']: + if res['exchange_rate'] and float(res['nb_of_dec_exchange_rate']) > 0: res['exchange_rate']= float(res['exchange_rate'])\ /float(res['nb_of_dec_exchange_rate']) return res diff --git a/cfonb/parser/statement.py b/cfonb/parser/statement.py index f33582e..319cc67 100644 --- a/cfonb/parser/statement.py +++ b/cfonb/parser/statement.py @@ -16,7 +16,7 @@ def parse(self, file_obj): # content result = {} for index, line in enumerate(file_lines): - + #print(f"at line number {index+1}") if line[0:2] == '01': row = Row(line)