From 36fcb3dc9dff25f947a7bb5e695541cdf459d181 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Sat, 1 Apr 2023 18:25:32 +0200 Subject: [PATCH] [IMP] improved handling of statements without transactions --- account_ebics/__manifest__.py | 2 +- account_ebics/models/ebics_file.py | 26 +++++++++++++------ .../__manifest__.py | 4 +-- .../wizards/account_statement_import.py | 9 ++++--- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/account_ebics/__manifest__.py b/account_ebics/__manifest__.py index 3452e3a..698b967 100644 --- a/account_ebics/__manifest__.py +++ b/account_ebics/__manifest__.py @@ -3,7 +3,7 @@ { "name": "EBICS banking protocol", - "version": "14.0.1.1.1", + "version": "14.0.1.1.2", "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 36065e3..ad4e301 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -87,7 +87,7 @@ class EbicsFile(models.Model): return super(EbicsFile, self).unlink() def set_to_draft(self): - return self.write({"state": "draft"}) + return self.write({"state": "draft", "note": False}) def set_to_done(self): return self.write({"state": "done"}) @@ -219,10 +219,11 @@ class EbicsFile(models.Model): error_cnt += 1 elif notif["type"] == "warning": warning_cnt += 1 - parts = [notif[k] for k in notif if k in ("message", "details")] + parts = [ + notif[k] for k in notif if k in ("message", "details") and notif[k] + ] self.note_process += "\n".join(parts) self.note_process += "\n\n" - self.note_process += "\n" if error_cnt: self.note_process += ( _("Number of errors detected during import: %s: ") % error_cnt @@ -233,8 +234,9 @@ class EbicsFile(models.Model): _("Number of watnings detected during import: %s: ") % warning_cnt ) if st_cnt: - self.note_process += "\n\n" - self.note_process += _("%s bank statements have been imported: ") % st_cnt + if self.note_process: + self.note_process += "\n\n" + self.note_process += _("%s bank statement(s) have been imported: ") % st_cnt self.note_process += "\n" for st_data in sts_data: self.note_process += ("\n%s, %s (%s)") % ( @@ -293,6 +295,8 @@ class EbicsFile(models.Model): "account.action_bank_statement_tree" ) result_action["context"] = safe_eval(result_action["context"]) + + transactions = False statement_ids = [] notifications = [] for i, wiz_vals in enumerate(wiz_vals_list, start=1): @@ -316,7 +320,10 @@ class EbicsFile(models.Model): fn=statement_filename, ) wiz.import_single_file(file_data, result) - if not result["statement_ids"]: + if result["statement_ids"]: + transactions = True + statement_ids.extend(result["statement_ids"]) + elif not result.get("no_transactions"): message = msg_hdr.format(_("Warning")) message += _( "You have already imported this file, or this file " @@ -328,8 +335,7 @@ class EbicsFile(models.Model): "message": message, } ] - else: - statement_ids.extend(result["statement_ids"]) + transactions = True notifications.extend(result["notifications"]) except UserError as e: @@ -353,6 +359,10 @@ class EbicsFile(models.Model): } ] + if not transactions: + message = _("This file doesn't contain any transaction.") + notifications = [{"type": "warning", "message": message, "details": ""}] + self.note = message result_action["context"]["notifications"] = notifications result_action["domain"] = [("id", "in", statement_ids)] return self._process_result_action(result_action) diff --git a/account_ebics_oca_statement_import/__manifest__.py b/account_ebics_oca_statement_import/__manifest__.py index a141b7a..ce8c37f 100644 --- a/account_ebics_oca_statement_import/__manifest__.py +++ b/account_ebics_oca_statement_import/__manifest__.py @@ -1,10 +1,10 @@ -# Copyright 2020 Noviat. +# Copyright 2009-2023 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). { "name": "account_ebics with OCA Bank Statement Imoort", "summary": "Use OCA Bank Statement Import with account_ebics", - "version": "14.0.1.0.0", + "version": "14.0.1.0.1", "author": "Noviat", "category": "Hidden", "license": "LGPL-3", diff --git a/account_ebics_oca_statement_import/wizards/account_statement_import.py b/account_ebics_oca_statement_import/wizards/account_statement_import.py index cc49e00..d88b825 100644 --- a/account_ebics_oca_statement_import/wizards/account_statement_import.py +++ b/account_ebics_oca_statement_import/wizards/account_statement_import.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Noviat. +# Copyright 2009-2023 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). import logging @@ -53,8 +53,9 @@ class AccountStatementImport(models.TransientModel): break if not transactions: message = _("This file doesn't contain any transaction.") - st_line_ids = [] - notifications = {"type": "warning", "message": message, "details": ""} - return st_line_ids, [notifications] + result["notifications"].append( + {"type": "warning", "message": message, "details": ""} + ) + result["no_transactions"] = True return super()._create_bank_statements(stmts_vals, result)