[ADD]Account Bank Statement Import CCoop addon

This commit is contained in:
Fabien BOURGEOIS 2018-09-12 15:29:15 +02:00
parent 09f56b8cfd
commit a6b93ab061
7 changed files with 260 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
from . import wizard

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
{
'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']
}

View File

@ -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 ""

View File

@ -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"

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
from . import account_bank_statement_import

View File

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
""" 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]

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
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 <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Forms -->
<record id="account_bank_statement_import_view_inherit_ccoop" model="ir.ui.view">
<field name="name">Account Bank Statement Import Form adaptations</field>
<field name="model">account.bank.statement.import</field>
<field name="inherit_id"
ref="account_bank_statement_import.account_bank_statement_import_view" />
<field name="arch" type="xml">
<xpath expr="//ul[@id='statement_format']" position="inside">
<li>Crédit Coop (.CSV)</li>
</xpath>
</field>
</record>
</data>
</odoo>