Browse Source
Merge pull request #151 from beescoop/12.0-mig-beesdoo_crelan_csv
Merge pull request #151 from beescoop/12.0-mig-beesdoo_crelan_csv
[12.0] [MIG] beesdoo_crelan_csvpull/153/head
Rémy Taymans
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 201 additions and 0 deletions
-
2beesdoo_crelan_csv/__init__.py
-
23beesdoo_crelan_csv/__manifest__.py
-
46beesdoo_crelan_csv/i18n/fr_BE.po
-
1beesdoo_crelan_csv/models/__init__.py
-
10beesdoo_crelan_csv/models/account_journal.py
-
1beesdoo_crelan_csv/wizard/__init__.py
-
118beesdoo_crelan_csv/wizard/import_crelan_csv.py
@ -0,0 +1,2 @@ |
|||||
|
from . import models |
||||
|
from . import wizard |
@ -0,0 +1,23 @@ |
|||||
|
# Copyright 2016 - 2020 BEES coop SCRLfs |
||||
|
# - Thibault Francois (thibault@françois.be) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
{ |
||||
|
'name': "Beescoop Crelan Import module", |
||||
|
|
||||
|
'summary': """ |
||||
|
Import Crelan CSV Wizard |
||||
|
""", |
||||
|
|
||||
|
'description': """ |
||||
|
""", |
||||
|
|
||||
|
'author': "Beescoop - Cellule IT", |
||||
|
'website': "https://github.com/beescoop/Obeesdoo", |
||||
|
|
||||
|
'category': 'Accounting & Finance', |
||||
|
'version': '12.0.1.0.0', |
||||
|
|
||||
|
'depends': ['account_bank_statement_import'], |
||||
|
'installable': True, |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * beesdoo_crelan_csv |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 9.0c\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2016-11-13 15:19+0000\n" |
||||
|
"PO-Revision-Date: 2016-11-13 15:19+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: beesdoo_crelan_csv |
||||
|
#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:57 |
||||
|
#, python-format |
||||
|
msgid "Bank Statement from %s to %s" |
||||
|
msgstr "Bank Statement from %s to %s" |
||||
|
|
||||
|
#. module: beesdoo_crelan_csv |
||||
|
#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:38 |
||||
|
#, python-format |
||||
|
msgid "Communication" |
||||
|
msgstr "Communication" |
||||
|
|
||||
|
#. module: beesdoo_crelan_csv |
||||
|
#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:37 |
||||
|
#, python-format |
||||
|
msgid "Counter Party Account" |
||||
|
msgstr "Counter Party Account" |
||||
|
|
||||
|
#. module: beesdoo_crelan_csv |
||||
|
#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:36 |
||||
|
#, python-format |
||||
|
msgid "Counter Party Name" |
||||
|
msgstr "Counter Party Name" |
||||
|
|
||||
|
#. module: beesdoo_crelan_csv |
||||
|
#: model:ir.model,name:beesdoo_crelan_csv.model_account_bank_statement_import |
||||
|
msgid "Import Bank Statement" |
||||
|
msgstr "Import d'un relevé bancaire" |
||||
|
|
@ -0,0 +1 @@ |
|||||
|
from . import account_journal |
@ -0,0 +1,10 @@ |
|||||
|
from odoo import models |
||||
|
|
||||
|
|
||||
|
class AccountJournal(models.Model): |
||||
|
_inherit = "account.journal" |
||||
|
|
||||
|
def _get_bank_statements_available_import_formats(self): |
||||
|
formats_list = super()._get_bank_statements_available_import_formats() |
||||
|
formats_list.append('Crelan') |
||||
|
return formats_list |
@ -0,0 +1 @@ |
|||||
|
from . import import_crelan_csv |
@ -0,0 +1,118 @@ |
|||||
|
from io import StringIO |
||||
|
import csv |
||||
|
import datetime |
||||
|
import hashlib |
||||
|
from odoo import models, _ |
||||
|
|
||||
|
ACCOUNT = "Compte donneur d'ordre" |
||||
|
CURRENCY = "Devise" |
||||
|
DATE = "Date" |
||||
|
AMOUNT = "Montant" |
||||
|
COUNTERPART_NUMBER = "Compte contrepartie" |
||||
|
COUNTERPART_NAME = "Contrepartie" |
||||
|
COMMUNICATION = "Communication" |
||||
|
TRANSACTION_TYPE = "Type d'opération" |
||||
|
|
||||
|
class CodaBankStatementImport(models.TransientModel): |
||||
|
_inherit = 'account.bank.statement.import' |
||||
|
|
||||
|
_date_format = "%d/%m/%Y" |
||||
|
|
||||
|
_decimal_sep = "." |
||||
|
_csv_delimiter = ";" |
||||
|
_csv_quote = '"' |
||||
|
|
||||
|
_header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'opération", |
||||
|
'Communication', "Compte donneur d'ordre"] |
||||
|
|
||||
|
|
||||
|
def _generate_note_crelan(self, move): |
||||
|
notes = [] |
||||
|
notes.append("%s: %s" % (_('Counter Party Name'), move[COUNTERPART_NAME])) |
||||
|
notes.append("%s: %s" % (_('Counter Party Account'), move[COUNTERPART_NUMBER])) |
||||
|
notes.append("%s: %s" % (_('Communication'), move[COMMUNICATION])) |
||||
|
return '\n'.join(notes) |
||||
|
|
||||
|
def _get_move_value_crelan(self, move, sequence): |
||||
|
move_data = { |
||||
|
'name': move[TRANSACTION_TYPE] + ": " + move[COMMUNICATION], |
||||
|
'note': self._generate_note_crelan(move), |
||||
|
'date': self._to_iso_date(move[DATE]), |
||||
|
'amount': float(move[AMOUNT]), |
||||
|
'account_number': move[COUNTERPART_NUMBER], # Ok |
||||
|
'partner_name': move[COUNTERPART_NAME], # Ok |
||||
|
'ref': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME], |
||||
|
'sequence': sequence, # Ok |
||||
|
'unique_import_id': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + |
||||
|
move[COUNTERPART_NAME] + '-' + hashlib.new('md5', move[COMMUNICATION].encode()).hexdigest() |
||||
|
} |
||||
|
return move_data |
||||
|
|
||||
|
def _get_statement_data_crelan(self, balance_start, balance_end, begin_date, end_date): |
||||
|
statement_data = { |
||||
|
'name': _("Bank Statement from %s to %s") % (begin_date, end_date), |
||||
|
'date': self._to_iso_date(end_date), |
||||
|
'balance_start': balance_start, # Ok |
||||
|
'balance_end_real' : balance_end, # Ok |
||||
|
'transactions' : [] |
||||
|
} |
||||
|
return statement_data |
||||
|
|
||||
|
def _get_acc_number_crelan(self, acc_number): |
||||
|
# Check if we match the exact acc_number or the end of an acc number |
||||
|
journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) |
||||
|
if not journal or len(journal) > 1: # If not found or ambiguious |
||||
|
return acc_number |
||||
|
|
||||
|
return journal.bank_acc_number |
||||
|
|
||||
|
def _get_acc_balance_crelan(self, acc_number): |
||||
|
if not self.init_balance == None: |
||||
|
return self.init_balance |
||||
|
|
||||
|
journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) |
||||
|
currency = journal.currency_id or journal.company_id.currency_id |
||||
|
if not journal or len(journal) > 1: # If not found or ambiguious |
||||
|
self.init_balance = 0.0 |
||||
|
else: |
||||
|
lang = self._context.get('lang', 'en_US') |
||||
|
l = self.env['res.lang'].search([('code', '=', lang)]) |
||||
|
balance = journal.get_journal_dashboard_datas()['last_balance'][:-1] |
||||
|
self.init_balance = float(balance.replace(currency.symbol, '').strip().replace(l.thousands_sep, '').replace(l.decimal_point, '.')) |
||||
|
return self.init_balance |
||||
|
|
||||
|
def _to_iso_date(self, orig_date): |
||||
|
date_obj = datetime.datetime.strptime(orig_date, self._date_format) |
||||
|
return date_obj.strftime('%Y-%m-%d') |
||||
|
|
||||
|
def _parse_file(self, data_file): |
||||
|
|
||||
|
try: |
||||
|
csv_file = StringIO(data_file.decode()) |
||||
|
data = csv.DictReader(csv_file, delimiter=self._csv_delimiter, quotechar=self._csv_quote) |
||||
|
if not data.fieldnames == self._header: |
||||
|
raise ValueError() |
||||
|
except ValueError: |
||||
|
return super(CodaBankStatementImport, self)._parse_file(data_file) |
||||
|
|
||||
|
currency_code = False |
||||
|
account_number = False |
||||
|
self.init_balance = None |
||||
|
begin_date = False |
||||
|
end_date = False |
||||
|
|
||||
|
transactions = [] |
||||
|
i = 1 |
||||
|
sum_transaction = 0 |
||||
|
for statement in data: |
||||
|
begin_date = begin_date or statement[DATE] |
||||
|
end_date = statement[DATE] |
||||
|
account_number = statement[ACCOUNT] |
||||
|
balance = self._get_acc_balance_crelan(account_number) |
||||
|
currency_code = statement[CURRENCY] |
||||
|
transactions.append(self._get_move_value_crelan(statement, i)) |
||||
|
sum_transaction += float(statement[AMOUNT]) |
||||
|
i += 1 |
||||
|
stmt = self._get_statement_data_crelan(balance, balance + sum_transaction, begin_date, end_date) |
||||
|
stmt['transactions'] = transactions |
||||
|
return currency_code, self._get_acc_number_crelan(account_number), [stmt] |
Write
Preview
Loading…
Cancel
Save
Reference in new issue