From f1dc04fb427847cb8d8d3c833e5a3aae532680fc Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Wed, 15 Jul 2020 20:48:15 +0200 Subject: [PATCH] fix ebics.file download handler --- account_ebics/models/ebics_file.py | 80 ++++++++----------- .../wizards/account_bank_statement_import.py | 4 +- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/account_ebics/models/ebics_file.py b/account_ebics/models/ebics_file.py index 1a8e810..7efb3ef 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -139,7 +139,39 @@ class EbicsFile(models.Model): "\nPlease install module '%s'") % (self.format_id.name, module)) - def _process_result_action(self, ctx): + def _process_result_action(self, res): + notifications = [] + st_line_ids = [] + statement_ids = [] + if res.get('context'): + notifications = res['context'].get('notifications', []) + st_line_ids = res['context'].get('statement_line_ids', []) + if notifications: + for notif in notifications: + parts = [] + for k in ['type', 'message', 'details']: + if notif.get(k): + msg = '%s: %s' % (k, notif[k]) + parts.append(msg) + self.note_process += '\n'.join(parts) + self.note_process += '\n' + self.note_process += '\n' + if st_line_ids: + self.env.cr.execute( + """ + SELECT DISTINCT statement_id + FROM account_bank_statement_line + WHERE id IN %s + """ + % (tuple(st_line_ids),) + ) + statement_ids = list(self.env.cr.fetchall()[0]) + self.note_process += _( + "Number of Bank Statements: %s" + ) % len(statement_ids) + if statement_ids: + self.sudo().bank_statement_ids = [(6, 0, statement_ids)] + ctx = dict(self.env.context, statement_ids=statement_ids) module = __name__.split('addons.')[1].split('.')[0] result_view = self.env.ref('%s.ebics_file_view_form_result' % module) return { @@ -185,28 +217,7 @@ class EbicsFile(models.Model): wiz_ctx = dict(self.env.context, active_model='ebics.file') wiz = self.env[wiz_model].with_context(wiz_ctx).create(wiz_vals) res = wiz.import_file() - notifications = [] - statement_ids = [] - if res.get('context'): - notifications = res['context'].get('notifications', []) - statement_ids = res['context'].get('statement_ids', []) - if notifications: - for notif in notifications: - parts = [] - for k in ['type', 'message', 'details']: - if notif.get(k): - msg = '%s: %s' % (k, notif[k]) - parts.append(msg) - self.note_process += '\n'.join(parts) - self.note_process += '\n' - self.note_process += '\n' - self.note_process += _( - "Number of Bank Statements: %s" - ) % len(statement_ids) - if statement_ids: - self.bank_statement_ids = [(6, 0, statement_ids)] - ctx = dict(self._context, statement_ids=statement_ids) - return self._process_result_action(ctx) + return self._process_result_action(res) @staticmethod def _unlink_cfonb120(self): @@ -250,28 +261,7 @@ class EbicsFile(models.Model): raise UserError(_( "No financial journal found for Company Bank Account %s" ) % bank_account) - notifications = [] - statement_ids = [] - if res.get('context'): - notifications = res['context'].get('notifications', []) - statement_ids = res['context'].get('statement_ids', []) - if notifications: - for notif in notifications: - parts = [] - for k in ['type', 'message', 'details']: - if notif.get(k): - msg = '%s: %s' % (k, notif[k]) - parts.append(msg) - self.note_process += '\n'.join(parts) - self.note_process += '\n' - self.note_process += '\n' - self.note_process += _( - "Number of Bank Statements: %s" - ) % len(statement_ids) - if statement_ids: - self.bank_statement_ids = [(6, 0, statement_ids)] - ctx = dict(self._context, statement_ids=statement_ids) - return self._process_result_action(ctx) + return self._process_result_action(res) @staticmethod def _unlink_camt053(self): diff --git a/account_ebics/wizards/account_bank_statement_import.py b/account_ebics/wizards/account_bank_statement_import.py index 3e1d331..937f807 100644 --- a/account_ebics/wizards/account_bank_statement_import.py +++ b/account_ebics/wizards/account_bank_statement_import.py @@ -51,12 +51,12 @@ class AccountBankStatementImport(models.TransientModel): break if not transactions: message = _('This file doesn\'t contain any transaction.') - statement_ids = [] + st_line_ids = [] notifications = { 'type': 'warning', 'message': message, 'details': '' } - return statement_ids, [notifications] + return st_line_ids, [notifications] return super()._create_bank_statements(stmts_vals)