From 000d14a7dc9ec0c0e168ad7acad92b44f2e7cff4 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Sat, 30 Jan 2021 19:16:52 +0100 Subject: [PATCH] [14.0][MIG]account_ebics --- account_ebics/README.rst | 20 +++++-- account_ebics/models/ebics_file.py | 86 ++++++++++++++++++++++++----- account_ebics/wizards/ebics_xfer.py | 2 +- 3 files changed, 90 insertions(+), 18 deletions(-) diff --git a/account_ebics/README.rst b/account_ebics/README.rst index e5e5d5d..634a617 100644 --- a/account_ebics/README.rst +++ b/account_ebics/README.rst @@ -59,7 +59,7 @@ We also recommend to consider the installation of the following modules: | -- account_bank_statement_import_camt_oca +- account_statement_import_camt Required to handle camt.052 and camt.054 files. @@ -67,13 +67,25 @@ We also recommend to consider the installation of the following modules: | -- account_bank_statement_import_helper +- account_statement_import_helper - Required if you are processing bank statements with local bank account numbers (e.g. french CFONB files). + Required if you are processing bank statements with local bank account numbers (e.g. french CFONB files) + and using import parsers based upon the OCA account_statement_import module. The import helper will match the local bank account number with the IBAN number specified on the Odoo Financial journal. - Cf. https://github.com/noviat-apps + Cf. https://github.com/Noviat/noviat-apps + +| + +- account_bank_statement_import_helper + + Required if you are processing bank statements with local bank account numbers + and using import parsers based upon the Odoo Enterprise account_bank_statement_import module. + + The import helper will match the local bank account number with the IBAN number specified on the Odoo Financial journal. + + Cf. https://github.com/Noviat/noviat-apps | diff --git a/account_ebics/models/ebics_file.py b/account_ebics/models/ebics_file.py index d20bf4c..378d23d 100644 --- a/account_ebics/models/ebics_file.py +++ b/account_ebics/models/ebics_file.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Noviat. +# Copyright 2009-2021 Noviat. # License LGPL-3 or later (http://www.gnu.org/licenses/lpgl). import base64 @@ -138,16 +138,19 @@ class EbicsFile(models.Model): } return res - def _check_import_module(self, module): - mod = self.env['ir.module.module'].search( + def _check_import_module(self, module, raise_if_not_found=True): + mod = self.env['ir.module.module'].sudo().search( [('name', '=like', module), ('state', '=', 'installed')]) if not mod: - raise UserError(_( - "The module to process the '%s' format is not installed " - "on your system. " - "\nPlease install module '%s'") - % (self.format_id.name, module)) + if raise_if_not_found: + raise UserError(_( + "The module to process the '%s' format is not installed " + "on your system. " + "\nPlease install module '%s'") + % (self.format_id.name, module)) + return False + return True def _process_result_action(self, res): notifications = [] @@ -287,7 +290,7 @@ class EbicsFile(models.Model): @staticmethod def _process_camt052(self): - import_module = 'account_bank_statement_import_camt_oca' + import_module = 'account_statement_import_camt' self._check_import_module(import_module) return self._process_camt053(self) @@ -301,7 +304,7 @@ class EbicsFile(models.Model): @staticmethod def _process_camt054(self): - import_module = 'account_bank_statement_import_camt_oca' + import_module = 'account_statement_import_camt' self._check_import_module(import_module) return self._process_camt053(self) @@ -315,10 +318,67 @@ class EbicsFile(models.Model): @staticmethod def _process_camt053(self): - import_module = 'account_bank_statement_import_camt%' - self._check_import_module(import_module) - wiz_model = 'account.bank.statement.import' + modules = [ + ('oca', 'account_statement_import_camt'), + ('oe', 'account_bank_statement_import_camt'), + ] + found = False + for src, mod in modules: + if self._check_import_module(mod, raise_if_not_found=False): + found = True + break + if not found: + raise UserError(_( + "The module to process the '%s' format is not installed " + "on your system. " + "\nPlease install one of the following modules: \n%s." + ) % (self.format_id.name, ', '.join([x[1] for x in modules])) + ) + if src == 'oca': + self._process_camt053_oca() + else: + self._process_camt053_oe() + def _process_camt053_oca(self): + wiz_model = 'account.statement.import' + wiz_vals = { + 'statement_filename': self.name, + 'statement_file': self.data, + } + 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_button() + ctx = res.get('context') + import pdb; pdb.set_trace() + if (res.get('res_model') + == 'account.bank.statement.import.journal.creation'): + message = _( + "Error detected while importing statement %s.\n" + ) % self.name + message += _("No financial journal found.") + details = _( + 'Bank account number: %s' + ) % ctx.get('default_bank_acc_number') + result['context']['notifications'].extend([{ + 'type': 'warning', + 'message': message, + 'details': details, + }]) + result['context']['statement_line_ids'].extend( + ctx['statement_line_ids']) + result['context']['notifications'].extend( + ctx['notifications']) + return self._process_result_action(result) + + def _process_camt053_oe(self): + wiz_model = 'account.bank.statement.import' wiz_vals = { 'attachment_ids': [(0, 0, {'name': self.name, 'datas': self.data, diff --git a/account_ebics/wizards/ebics_xfer.py b/account_ebics/wizards/ebics_xfer.py index 1a38549..b0fed84 100644 --- a/account_ebics/wizards/ebics_xfer.py +++ b/account_ebics/wizards/ebics_xfer.py @@ -298,7 +298,7 @@ class EbicsXfer(models.TransientModel): suffix = self.format_id.suffix fn = self.upload_fname if not fn.endswith(suffix): - fn = '.'.join[fn, suffix] + fn = '.'.join([fn, suffix]) ef_vals = { 'name': self.upload_fname, 'data': self.upload_data,