From 2291e9d230641ad9acf24adb6ff855a0b1583366 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Thu, 16 Jul 2020 23:32:20 +0200 Subject: [PATCH] cfonb multibank statement support --- account_ebics/models/ebics_file.py | 50 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/account_ebics/models/ebics_file.py b/account_ebics/models/ebics_file.py index 7efb3ef..2d8c56f 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -162,8 +162,8 @@ class EbicsFile(models.Model): SELECT DISTINCT statement_id FROM account_bank_statement_line WHERE id IN %s - """ - % (tuple(st_line_ids),) + """, + (tuple(st_line_ids),) ) statement_ids = list(self.env.cr.fetchall()[0]) self.note_process += _( @@ -189,35 +189,51 @@ class EbicsFile(models.Model): @staticmethod def _process_cfonb120(self): """ - TODO: - adapt OCA import logic to find correct journal on the basis - of both account number and currency. - Prompt for journal in case the journal is not found. + We do not support the standard _journal_creation_wizard since a single + cfonb120 file may contain statements from different legal entities. """ import_module = 'account_bank_statement_import_fr_cfonb' self._check_import_module(import_module) wiz_model = 'account.bank.statement.import' data_file = base64.b64decode(self.data) lines = data_file.split(b'\n') - att_vals = [] + attachments_vals = [] st_lines = b'' + transactions = False for line in lines: rec_type = line[0:2] acc_number = line[21:32] st_lines += line + b'\n' + if rec_type == b'04': + transactions = True if rec_type == b'07': - fn = '_'.join([acc_number.decode(), self.name]) - att_vals.append({ - 'name': fn, - 'store_fname': fn, - 'datas': base64.b64encode(st_lines) - }) + if transactions: + fn = '_'.join([acc_number.decode(), self.name]) + attachments_vals.append({ + 'name': fn, + 'store_fname': fn, + 'datas': base64.b64encode(st_lines) + }) st_lines = b'' - wiz_vals = {'attachment_ids': [(0, 0, x) for x in att_vals]} + transactions = False + result = { + 'type': 'ir.actions.client', + 'tag': 'bank_statement_reconciliation_view', + 'context': {'statement_line_ids': [], + 'company_ids': self.env.user.company_ids.ids, + 'notifications': []}, + } 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() - return self._process_result_action(res) + for attachment_vals in attachments_vals: + wiz_vals = {'attachment_ids': [(0, 0, attachment_vals)]} + wiz = self.env[wiz_model].with_context(wiz_ctx).create(wiz_vals) + res = wiz.import_file() + ctx = res.get('context') + result['context']['statement_line_ids'].extend( + ctx['statement_line_ids']) + result['context']['notifications'].extend( + ctx['notifications']) + return self._process_result_action(result) @staticmethod def _unlink_cfonb120(self):