From f835ab7af8c70729f7599e4086266e4ae42a0d43 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Mon, 15 Jul 2024 22:50:51 +0200 Subject: [PATCH] [FIX]account_ebics - fix split cfonb120 files --- account_ebics/__manifest__.py | 2 +- account_ebics/models/ebics_file.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/account_ebics/__manifest__.py b/account_ebics/__manifest__.py index b9bd17d..3daa03c 100644 --- a/account_ebics/__manifest__.py +++ b/account_ebics/__manifest__.py @@ -3,7 +3,7 @@ { "name": "EBICS banking protocol", - "version": "17.0.1.1.0", + "version": "17.0.1.1.1", "license": "LGPL-3", "author": "Noviat", "website": "https://www.noviat.com", diff --git a/account_ebics/models/ebics_file.py b/account_ebics/models/ebics_file.py index 1979643..29a3370 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -240,7 +240,7 @@ class EbicsFile(models.Model): if statements: statements.write({"import_format": file_format}) statements = self._statement_duplicate_check(res, statements) - else: + elif not notifications: notifications.append( { "type": "warning", @@ -347,7 +347,8 @@ class EbicsFile(models.Model): self._check_import_module(import_module) res = {"statement_ids": [], "notifications": []} st_datas = self._split_cfonb(res) - self._process_bank_statement_oca(res, st_datas) + if st_datas: + self._process_bank_statement_oca(res, st_datas) return self._process_download_result(res, file_format="cfonb120") def _unlink_cfonb120(self): @@ -363,7 +364,19 @@ class EbicsFile(models.Model): """ datas = [] file_data = base64.b64decode(self.data) - lines = file_data.split(b"\n") + file_data.replace(b"\n", b"").replace(b"\r", b"") + if len(file_data) % 120: + message = _( + "Incorrect CFONB120 file:\n" + "the file is not divisible in 120 char lines" + ) + res["notifications"].append({"type": "error", "message": message}) + return datas + + lines = [] + for i in range(0, len(file_data), 120): + lines.append(file_data[i : i + 120]) + st_lines = b"" transactions = False for line in lines: