Skip to content

Commit 9bf77bd

Browse files
author
Hong-Thai Nguyen
authored
Merge pull request #1 from thaichat04/fix-parsing
Fixing parsing new norme
2 parents abb9c33 + 53c1bd0 commit 9bf77bd

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

cfonb/parser/common.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ def parse(self, line):
9797
if len(line) > self.size and len(line.strip()) <= self.size:
9898
line = line[:self.size]
9999
if len(line) != self.size:
100-
raise ParsingError("Invalid line: >%s<. the len should be %s"
101-
"instead of %s" % (line, self.size, len(line)))
100+
if self._code == '05' and len(line) == 78:
101+
line += ' ' * 42
102+
else:
103+
raise ParsingError("Invalid line: >%s<. the len should be %s"
104+
"instead of %s" % (line, self.size, len(line)))
102105
match = self.re.match(line)
103106
# re check
104107
if match is None:
@@ -125,15 +128,15 @@ class ParserContent01(Parser):
125128
_regex = [
126129
('record_code', '(01)', 2),
127130
('bank_code', G_N, 5),
128-
('_1', G__, 4),
131+
('_1', G_AN_, 4),
129132
('desk_code', G_N, 5),
130133
('currency_code', G_A_, 3),
131134
('nb_of_dec', G_N_, 1),
132135
('_2', G__, 1),
133136
('account_nb', G_AN, 11),
134137
('_3', G__, 2),
135138
('prev_date', G_N, 6),
136-
('_4', G__, 50),
139+
('_4', G_ALL, 50),
137140
('prev_amount', G_AMT, 14),
138141
('_5', G_ALL, 16),
139142
]
@@ -194,7 +197,7 @@ class ParserContent05(Parser):
194197
('account_nb', G_AN, 11),
195198
('operation_code', G_AN, 2),
196199
('operation_date', G_N, 6),
197-
('_2', G__, 5),
200+
('_2', G_N_, 5),
198201
('qualifier', G_AN, 3),
199202
('additional_info', G_ALL, 70),
200203
('_3', G__, 2),
@@ -212,17 +215,17 @@ class ParserContent07(Parser):
212215
_regex = [
213216
('record_code', '(07)', 2),
214217
('bank_code', G_N, 5),
215-
('_1', G__, 4),
218+
('_1', G_AN_, 4),
216219
('desk_code', G_N, 5),
217220
('currency_code', G_A_, 3),
218221
('nb_of_dec', G_N_, 1),
219222
('_2', G__, 1),
220223
('account_nb', G_AN, 11),
221224
('_3', G__, 2),
222225
('next_date', G_N, 6),
223-
('_4', G__, 50),
226+
('_4', G_ALL, 50),
224227
('next_amount', G_AMT, 14),
225-
('_5', G__, 16),
228+
('_5', G_ALL, 16),
226229
]
227230

228231
def _post(self, res):
@@ -354,7 +357,7 @@ def _post(self, res):
354357
res = super(ParserMMO, self)._post(res)
355358
res['equivalent_amount'] = float(res['equivalent_amount'])\
356359
/float(res['nb_of_dec_amount'])
357-
if res['exchange_rate']:
360+
if res['exchange_rate'] and float(res['nb_of_dec_exchange_rate']) > 0:
358361
res['exchange_rate']= float(res['exchange_rate'])\
359362
/float(res['nb_of_dec_exchange_rate'])
360363
return res

cfonb/parser/statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def parse(self, file_obj):
1616
# content
1717
result = {}
1818
for index, line in enumerate(file_lines):
19-
19+
#print(f"at line number {index+1}")
2020
if line[0:2] == '01':
2121
row = Row(line)
2222

0 commit comments

Comments
 (0)