diff --git a/account_bank_statement_import_ccoop/__init__.py b/account_bank_statement_import_ccoop/__init__.py new file mode 100644 index 0000000..4cbbaff --- /dev/null +++ b/account_bank_statement_import_ccoop/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import wizard diff --git a/account_bank_statement_import_ccoop/__manifest__.py b/account_bank_statement_import_ccoop/__manifest__.py new file mode 100644 index 0000000..d9504fe --- /dev/null +++ b/account_bank_statement_import_ccoop/__manifest__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + 'name': 'Account Bank Statement Import Crédit Coopératif', + 'summary': 'Account Bank Statement Import Crédit Coopératif', + 'description': """ Account Bank Statement Import Crédit Coopératif : + * 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', + 'category': 'Banking addons', + 'author': 'Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': ['account_bank_statement_import'], + 'data': ['wizard/account_bank_statement_import_views.xml'] +} 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 new file mode 100644 index 0000000..d4e7da3 --- /dev/null +++ b/account_bank_statement_import_ccoop/i18n/account_bank_statement_import_ccoop.pot @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_bank_statement_import_ccoop +# +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" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_bank_statement_import_ccoop +#: model:ir.ui.view,arch_db:account_bank_statement_import_ccoop.account_bank_statement_import_view_inherit_ccoop +msgid "Crédit Coop (.CSV)" +msgstr "" + +#. module: account_bank_statement_import_ccoop +#: model:ir.model,name:account_bank_statement_import_ccoop.model_account_bank_statement_import +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 new file mode 100644 index 0000000..506d612 --- /dev/null +++ b/account_bank_statement_import_ccoop/i18n/fr.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_bank_statement_import_ccoop +# +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" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_bank_statement_import_ccoop +#: model:ir.ui.view,arch_db:account_bank_statement_import_ccoop.account_bank_statement_import_view_inherit_ccoop +msgid "Crédit Coop (.CSV)" +msgstr "Crédit Coop (.CSV)" + +#. module: account_bank_statement_import_ccoop +#: model:ir.model,name:account_bank_statement_import_ccoop.model_account_bank_statement_import +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/__init__.py b/account_bank_statement_import_ccoop/wizard/__init__.py new file mode 100644 index 0000000..c7a60a7 --- /dev/null +++ b/account_bank_statement_import_ccoop/wizard/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import account_bank_statement_import 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 new file mode 100644 index 0000000..63cf63d --- /dev/null +++ b/account_bank_statement_import_ccoop/wizard/account_bank_statement_import.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" Bank statement import : CSV from Credit Coop """ + +import time +from mimetypes import guess_type +import csv +from odoo import models, api, _ +from odoo.exceptions import ValidationError + +def str2float(string): + """ Transform CSV string to Python float """ + return float(string.replace(',', '.')) + + +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] + + @api.model + def _get_coop_transaction(self, account_number, line): + """ Prepare transaction line """ + return {'name': line[1], + 'date': time.strftime('%Y-%m-%d', + time.strptime(line[0], '%d/%m/%y')), + 'amount': str2float(line[3] or line[4]), + 'unique_import_id': line[1], + 'account_number': account_number, + 'note': line[5], + 'ref': line[2]} + + @api.model + def _get_ccop_processed(self, data): + """ Prepare and return CCoop transaction """ + currency = data[1][2].split(' : ')[1] + account_number = data[1][0].split(' : ')[1] + if not len(data[-1]): # If last line is empty, remove it + data.pop() + bank_statement_data = { + 'date': time.strftime( + '%Y-%m-%d', time.strptime(data[0][3].split(' : ')[1], '%d/%m/%Y')), + 'balance_start': str2float(data[-1][-1]), + 'balance_end_real': str2float(data[3][-1]) + } + bank_statement_data['name'] = '%s - %s' % (account_number, + bank_statement_data['date']) + bank_statement_data['transactions'] = [ + self._get_coop_transaction(account_number, l) for l in data[5:-1] + ] + return currency, account_number, bank_statement_data + + + def _parse_file(self, data_file): + """ Implements parse_file from parent, returning the required triplet """ + data = self._load_ccop_csv(data_file) + currency, account_number, bank_statement_data = self._get_ccop_processed(data) + return currency, account_number, [bank_statement_data] diff --git a/account_bank_statement_import_ccoop/wizard/account_bank_statement_import_views.xml b/account_bank_statement_import_ccoop/wizard/account_bank_statement_import_views.xml new file mode 100644 index 0000000..51f9774 --- /dev/null +++ b/account_bank_statement_import_ccoop/wizard/account_bank_statement_import_views.xml @@ -0,0 +1,38 @@ + + + + + + + + + + Account Bank Statement Import Form adaptations + account.bank.statement.import + + + +
  • Crédit Coop (.CSV)
  • +
    +
    +
    + +
    +
    +