From d9c9fa52ff40842c8f270ea185d24887922c5f50 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Wed, 12 Sep 2018 17:25:05 +0200 Subject: [PATCH] [FIX]Account Bank Statment Import CCoop * Check CCoop CSV file, to allow import chain ; * Convert ISO to UTF8. --- .../__manifest__.py | 2 +- .../account_bank_statement_import_ccoop.pot | 10 ++----- .../i18n/fr.po | 10 ++----- .../wizard/account_bank_statement_import.py | 27 +++++++++++-------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/account_bank_statement_import_ccoop/__manifest__.py b/account_bank_statement_import_ccoop/__manifest__.py index d9504fe..1970349 100644 --- a/account_bank_statement_import_ccoop/__manifest__.py +++ b/account_bank_statement_import_ccoop/__manifest__.py @@ -22,7 +22,7 @@ * For CSV published by Crédit Coopératif on their website customer space ; * Adds option on bank import statement wizard ; * Checks and processes file.""", - 'version': '10.0.0.1.0', + 'version': '10.0.0.1.1', 'category': 'Banking addons', 'author': 'Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/account_bank_statement_import_ccoop/i18n/account_bank_statement_import_ccoop.pot b/account_bank_statement_import_ccoop/i18n/account_bank_statement_import_ccoop.pot index d4e7da3..676c9dd 100644 --- a/account_bank_statement_import_ccoop/i18n/account_bank_statement_import_ccoop.pot +++ b/account_bank_statement_import_ccoop/i18n/account_bank_statement_import_ccoop.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-12 13:28+0000\n" -"PO-Revision-Date: 2018-09-12 13:28+0000\n" +"POT-Creation-Date: 2018-09-12 15:22+0000\n" +"PO-Revision-Date: 2018-09-12 15:22+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -25,9 +25,3 @@ msgstr "" msgid "Import Bank Statement" msgstr "" -#. module: account_bank_statement_import_ccoop -#: code:addons/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py:41 -#, python-format -msgid "Invalid filetype, expected CSV" -msgstr "" - diff --git a/account_bank_statement_import_ccoop/i18n/fr.po b/account_bank_statement_import_ccoop/i18n/fr.po index 506d612..e2f8b7f 100644 --- a/account_bank_statement_import_ccoop/i18n/fr.po +++ b/account_bank_statement_import_ccoop/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-12 13:28+0000\n" -"PO-Revision-Date: 2018-09-12 15:28+0200\n" +"POT-Creation-Date: 2018-09-12 15:23+0000\n" +"PO-Revision-Date: 2018-09-12 15:23+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -25,9 +25,3 @@ msgstr "Crédit Coop (.CSV)" msgid "Import Bank Statement" msgstr "Import d'un relevé bancaire" -#. module: account_bank_statement_import_ccoop -#: code:addons/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py:41 -#, python-format -msgid "Invalid filetype, expected CSV" -msgstr "Type de fichier invalide, format CSV attendu" - diff --git a/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py b/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py index 63cf63d..56a7535 100644 --- a/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py +++ b/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py @@ -32,20 +32,23 @@ class AccountBankStatementImport(models.TransientModel): """ Bank statement import : CSV from Credit Coop """ _inherit = 'account.bank.statement.import' - @api.multi - def import_file(self): - """ Check filetype before loading data """ - self.ensure_one() - file_type = guess_type(self.filename)[0] - if file_type != 'text/csv': - raise ValidationError(_('Invalid filetype, expected CSV')) - return super(AccountBankStatementImport, self).import_file() - @api.model def _load_ccop_csv(self, data_file): """ Parses and load CSV from CCoop """ csv_data = csv.reader(data_file.split('\n'), delimiter=';') - return [line for line in csv_data] + return [[cell.decode('iso-8859-15').encode('utf8') for cell in line] + for line in csv_data] + + @api.model + def _check_load_ccoop(self, data_file): + """ Check filetype and CCoop before loading data """ + file_type = guess_type(self.filename)[0] + if file_type != 'text/csv': + return False + data = self._load_ccop_csv(data_file) + if not data[0][0].startswith('Code de la banque : '): + return False + return data @api.model def _get_coop_transaction(self, account_number, line): @@ -82,6 +85,8 @@ class AccountBankStatementImport(models.TransientModel): def _parse_file(self, data_file): """ Implements parse_file from parent, returning the required triplet """ - data = self._load_ccop_csv(data_file) + data = self._check_load_ccoop(data_file) + if not data: + return super(AccountBankStatementImport, self)._parse_file(data_file) currency, account_number, bank_statement_data = self._get_ccop_processed(data) return currency, account_number, [bank_statement_data]