Add module account_bank_statement_import_fr_hsbc_card
This commit is contained in:
35
account_bank_statement_import_fr_hsbc_card/README.rst
Normal file
35
account_bank_statement_import_fr_hsbc_card/README.rst
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
=======================================
|
||||||
|
Import French HSBC Card Bank Statements
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
This module allows you to import French HSBC credit cards bank statements (CSV version).
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
Create a bank journal dedicated to HSBC credit cards. Associate it with a new bank account on which you will set the account number to *HSBC_CARD_EUR*.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
In the dashboard of the *Accounting* menu, click on the button *Import Statement* located on the journal corresponding to the bank account of the statement file you are importing.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues
|
||||||
|
<https://github.com/akretion/odoo-usability/issues>`_. In case of trouble, please
|
||||||
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
|
help us smashing it by providing a detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
3
account_bank_statement_import_fr_hsbc_card/__init__.py
Normal file
3
account_bank_statement_import_fr_hsbc_card/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import wizard
|
||||||
16
account_bank_statement_import_fr_hsbc_card/__manifest__.py
Normal file
16
account_bank_statement_import_fr_hsbc_card/__manifest__.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2017 Akretion (http://www.akretion.com)
|
||||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'Import French HSBC Card Bank Statements',
|
||||||
|
'version': '10.0.1.0.0',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'author': "Akretion",
|
||||||
|
'website': 'http://www.akretion.com',
|
||||||
|
'summary': 'Import French HSBC Card Bank Statements in Odoo (CSV version)',
|
||||||
|
'depends': ['account_bank_statement_import'],
|
||||||
|
'data': ['views/account_bank_statement_import.xml'],
|
||||||
|
'installable': True,
|
||||||
|
}
|
||||||
69
account_bank_statement_import_fr_hsbc_card/i18n/nb_NO.po
Normal file
69
account_bank_statement_import_fr_hsbc_card/i18n/nb_NO.po
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Translation of Odoo Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
# * account_bank_statement_import_fr_cfonb
|
||||||
|
#
|
||||||
|
# Translators:
|
||||||
|
# OCA Transbot <transbot@odoo-community.org>, 2017
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Odoo Server 10.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2017-01-13 03:36+0000\n"
|
||||||
|
"PO-Revision-Date: 2017-01-13 03:36+0000\n"
|
||||||
|
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
|
||||||
|
"Language-Team: Norwegian Bokmål (Norway) (https://www.transifex.com/oca/teams/23907/nb_NO/)\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: \n"
|
||||||
|
"Language: nb_NO\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: code:addons/account_bank_statement_import_fr_cfonb/models/account_bank_statement_import.py:146
|
||||||
|
#, python-format
|
||||||
|
msgid "Account %s"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: model:ir.ui.view,arch_db:account_bank_statement_import_fr_cfonb.account_bank_statement_import_view
|
||||||
|
msgid "CFONB (French format, fixed-length text lines of 120 caracters)"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: model:ir.model,name:account_bank_statement_import_fr_cfonb.model_account_bank_statement_import
|
||||||
|
msgid "Import Bank Statement"
|
||||||
|
msgstr "Importer bankutsagn"
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: code:addons/account_bank_statement_import_fr_cfonb/models/account_bank_statement_import.py:70
|
||||||
|
#, python-format
|
||||||
|
msgid ""
|
||||||
|
"Line %d is %d caracters long. All lines of a CFONB bank statement file must "
|
||||||
|
"be 120 caracters long."
|
||||||
|
msgstr ""
|
||||||
|
"Linje %d er %d tegn langt. Alle linjer i en CFONB-bankutsagnsfil må være 120"
|
||||||
|
" tegn langt."
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: code:addons/account_bank_statement_import_fr_cfonb/models/account_bank_statement_import.py:110
|
||||||
|
#, python-format
|
||||||
|
msgid ""
|
||||||
|
"Only single-account files and single-currency files are supported for the "
|
||||||
|
"moment. It is not the case starting from line %d."
|
||||||
|
msgstr ""
|
||||||
|
"Kun enkeltkontofiler og enkeltmyntenhetsfiler støttes for øyeblikket. Dette "
|
||||||
|
"er ikke tilfellet fra og med linje %d og utover."
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: code:addons/account_bank_statement_import_fr_cfonb/models/account_bank_statement_import.py:99
|
||||||
|
#, python-format
|
||||||
|
msgid ""
|
||||||
|
"The 2 first letters of the first line are '%s'. A CFONB file should start "
|
||||||
|
"with '01'"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: account_bank_statement_import_fr_cfonb
|
||||||
|
#: code:addons/account_bank_statement_import_fr_cfonb/models/account_bank_statement_import.py:52
|
||||||
|
#, python-format
|
||||||
|
msgid "The file is empty."
|
||||||
|
msgstr "Filen er tom."
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<!--
|
||||||
|
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="account_bank_statement_import_view" model="ir.ui.view">
|
||||||
|
<field name="name">hsbc.fr.csv.account.bank.statement.import.form</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>French HSBC Credit Cards (CSV format)</li>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import account_bank_statement_import
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2017 Akretion (http://www.akretion.com)
|
||||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import unicodecsv
|
||||||
|
from tempfile import TemporaryFile
|
||||||
|
from datetime import datetime
|
||||||
|
from odoo import models, fields, api, _
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class AccountBankStatementImport(models.TransientModel):
|
||||||
|
_inherit = 'account.bank.statement.import'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _check_hsbc_card_csv(self, data_file):
|
||||||
|
return data_file.strip().startswith(
|
||||||
|
'Titulaire;Division;;Cpt Affaires;Num carte;')
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _parse_file(self, data_file):
|
||||||
|
""" Import a file in French HSBC CSV Credit card format"""
|
||||||
|
hsbc_csv = self._check_hsbc_card_csv(data_file)
|
||||||
|
if not hsbc_csv:
|
||||||
|
return super(AccountBankStatementImport, self)._parse_file(
|
||||||
|
data_file)
|
||||||
|
transactions = []
|
||||||
|
fileobj = TemporaryFile('w+')
|
||||||
|
fileobj.write(data_file)
|
||||||
|
fileobj.seek(0)
|
||||||
|
reader = unicodecsv.DictReader(
|
||||||
|
fileobj,
|
||||||
|
fieldnames=[
|
||||||
|
'company', 'division', 'empty', 'account',
|
||||||
|
'card_num', 'title', 'lastname', 'firstname',
|
||||||
|
'op_code', 'seller_type', 'seller', 'date', 'acc_date',
|
||||||
|
'hour', 'city', 'code', 'label', 'local_amount',
|
||||||
|
'local_currency', 'acc_amount', 'acc_currency'],
|
||||||
|
delimiter=';',
|
||||||
|
quoting=unicodecsv.QUOTE_MINIMAL,
|
||||||
|
encoding='latin1')
|
||||||
|
i = 0
|
||||||
|
start_balance = end_balance = 0.0
|
||||||
|
currency_code = 'EUR'
|
||||||
|
account_number = 'HSBC_CARD_EUR'
|
||||||
|
for line in reader:
|
||||||
|
i += 1
|
||||||
|
if i == 1:
|
||||||
|
continue # skip title line
|
||||||
|
_logger.debug("Line %d: %s" % (i, line))
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
# cleanup
|
||||||
|
for key, value in line.iteritems():
|
||||||
|
line[key] = value and value.strip() or False
|
||||||
|
if not line['date'] or not line['acc_amount']:
|
||||||
|
continue
|
||||||
|
labels = [
|
||||||
|
'%s %s' % (line['firstname'], line['lastname']),
|
||||||
|
'%s (%s)' % (line['seller'], line['seller_type']),
|
||||||
|
line['city']]
|
||||||
|
if line['local_currency'] != currency_code:
|
||||||
|
labels.append(
|
||||||
|
'%s %s' % (line['local_amount'], line['local_currency']))
|
||||||
|
name = ', '.join(labels)
|
||||||
|
amount = float(
|
||||||
|
line['acc_amount'].replace(',', '.').replace(' ', '')) * -1
|
||||||
|
end_balance += amount
|
||||||
|
date_dt = datetime.strptime(line['date'], '%d/%m/%Y')
|
||||||
|
date_str = fields.Date.to_string(date_dt)
|
||||||
|
if line[u'acc_currency'] != currency_code:
|
||||||
|
raise UserError(_(
|
||||||
|
"On line %d of the HSBC CSV file, the column "
|
||||||
|
"'Dev Cpt Affaires' contains '%s' instead of 'EUR'")
|
||||||
|
% (line['acc_currency'], i))
|
||||||
|
vals_line = {
|
||||||
|
'date': date_str,
|
||||||
|
'name': name,
|
||||||
|
'ref': False,
|
||||||
|
'unique_import_id': '%s-%s-%.2f-%s' % (
|
||||||
|
date_str, line['hour'], amount, name),
|
||||||
|
'amount': amount,
|
||||||
|
'partner_id': False,
|
||||||
|
}
|
||||||
|
transactions.append(vals_line)
|
||||||
|
vals_bank_statement = {
|
||||||
|
'name': _('HSBC Cards'),
|
||||||
|
'balance_start': start_balance,
|
||||||
|
'balance_end_real': end_balance,
|
||||||
|
'transactions': transactions,
|
||||||
|
}
|
||||||
|
fileobj.close()
|
||||||
|
# from pprint import pprint
|
||||||
|
# pprint(vals_bank_statement)
|
||||||
|
return currency_code, account_number, [vals_bank_statement]
|
||||||
Reference in New Issue
Block a user